Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 6 |
|
0.00% |
0 / 5 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ProfilePermissions | |
0.00% |
0 / 26 |
|
0.00% |
0 / 6 |
|
0.00% |
0 / 5 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| create | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| permissions | |
0.00% |
0 / 24 |
|
0.00% |
0 / 4 |
|
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Drupal\display_builder; |
| 6 | |
| 7 | use Drupal\Core\DependencyInjection\ContainerInjectionInterface; |
| 8 | use Drupal\Core\Entity\EntityTypeManagerInterface; |
| 9 | use Drupal\Core\StringTranslation\StringTranslationTrait; |
| 10 | use Symfony\Component\DependencyInjection\ContainerInterface; |
| 11 | |
| 12 | /** |
| 13 | * Provides dynamic permissions of the display_builder module. |
| 14 | */ |
| 15 | class ProfilePermissions implements ContainerInjectionInterface { |
| 16 | |
| 17 | use StringTranslationTrait; |
| 18 | |
| 19 | /** |
| 20 | * The entity type manager. |
| 21 | * |
| 22 | * @var \Drupal\Core\Entity\EntityTypeManagerInterface |
| 23 | */ |
| 24 | protected $entityTypeManager; |
| 25 | |
| 26 | /** |
| 27 | * Constructs a new ProfilePermissions instance. |
| 28 | * |
| 29 | * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager |
| 30 | * The entity type manager. |
| 31 | */ |
| 32 | public function __construct(EntityTypeManagerInterface $entity_type_manager) { |
| 33 | $this->entityTypeManager = $entity_type_manager; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * {@inheritdoc} |
| 38 | */ |
| 39 | public static function create(ContainerInterface $container): ProfilePermissions { |
| 40 | return new static($container->get('entity_type.manager')); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Returns an array of permissions. |
| 45 | * |
| 46 | * @return array |
| 47 | * An array of permissions keyed by permission name. |
| 48 | */ |
| 49 | public function permissions(): array { |
| 50 | $permissions = []; |
| 51 | // Generate permissions for each display builder. Warn the administrator |
| 52 | // that any of them are potentially unsafe. |
| 53 | /** @var \Drupal\display_builder\ProfileInterface[] $builders */ |
| 54 | $builders = $this->entityTypeManager->getStorage('display_builder_profile')->loadMultiple(); |
| 55 | \uasort($builders, 'Drupal\Core\Config\Entity\ConfigEntityBase::sort'); |
| 56 | |
| 57 | foreach ($builders as $builder) { |
| 58 | $permission = $builder->getPermissionName(); |
| 59 | $permissions[$permission] = [ |
| 60 | 'title' => $this->t( |
| 61 | 'Use the %label Display Builder profile', |
| 62 | [ |
| 63 | '%label' => $builder->label(), |
| 64 | ] |
| 65 | ), |
| 66 | 'description' => [ |
| 67 | '#prefix' => '<em>', |
| 68 | '#markup' => $this->t('Warning: This permission may have security implications depending on how the display builder is configured.'), |
| 69 | '#suffix' => '</em>', |
| 70 | ], |
| 71 | // This permission is generated on behalf of $builder display builder, |
| 72 | // therefore add this display builder as a config dependency. |
| 73 | 'dependencies' => [ |
| 74 | $builder->getConfigDependencyKey() => [ |
| 75 | $builder->getConfigDependencyName(), |
| 76 | ], |
| 77 | ], |
| 78 | ]; |
| 79 | } |
| 80 | |
| 81 | return $permissions; |
| 82 | } |
| 83 | |
| 84 | } |
Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not
necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once.
Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement
always has an else as part of its logical flow even if you didn't write one.
| 32 | public function __construct(EntityTypeManagerInterface $entity_type_manager) { |
| 33 | $this->entityTypeManager = $entity_type_manager; |
| 34 | } |
| 39 | public static function create(ContainerInterface $container): ProfilePermissions { |
| 40 | return new static($container->get('entity_type.manager')); |
| 50 | $permissions = []; |
| 51 | // Generate permissions for each display builder. Warn the administrator |
| 52 | // that any of them are potentially unsafe. |
| 53 | /** @var \Drupal\display_builder\ProfileInterface[] $builders */ |
| 54 | $builders = $this->entityTypeManager->getStorage('display_builder_profile')->loadMultiple(); |
| 55 | \uasort($builders, 'Drupal\Core\Config\Entity\ConfigEntityBase::sort'); |
| 56 | |
| 57 | foreach ($builders as $builder) { |
| 57 | foreach ($builders as $builder) { |
| 57 | foreach ($builders as $builder) { |
| 58 | $permission = $builder->getPermissionName(); |
| 57 | foreach ($builders as $builder) { |
| 58 | $permission = $builder->getPermissionName(); |
| 59 | $permissions[$permission] = [ |
| 60 | 'title' => $this->t( |
| 61 | 'Use the %label Display Builder profile', |
| 62 | [ |
| 63 | '%label' => $builder->label(), |
| 64 | ] |
| 65 | ), |
| 66 | 'description' => [ |
| 67 | '#prefix' => '<em>', |
| 68 | '#markup' => $this->t('Warning: This permission may have security implications depending on how the display builder is configured.'), |
| 69 | '#suffix' => '</em>', |
| 70 | ], |
| 71 | // This permission is generated on behalf of $builder display builder, |
| 72 | // therefore add this display builder as a config dependency. |
| 73 | 'dependencies' => [ |
| 74 | $builder->getConfigDependencyKey() => [ |
| 75 | $builder->getConfigDependencyName(), |
| 76 | ], |
| 77 | ], |
| 78 | ]; |
| 79 | } |
| 80 | |
| 81 | return $permissions; |