Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
0.00% |
0 / 41 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
||
| ProfileListBuilder | |
0.00% |
0 / 41 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 8 |
132 | |
0.00% |
0 / 1 |
||
| __construct | |
0.00% |
0 / 2 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 1 |
2 | |||||
| createInstance | |
0.00% |
0 / 5 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 1 |
2 | |||||
| getFormId | |
0.00% |
0 / 1 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 1 |
2 | |||||
| buildHeader | |
0.00% |
0 / 6 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 1 |
2 | |||||
| buildRow | |
0.00% |
0 / 12 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 1 |
12 | |||||
| render | |
0.00% |
0 / 6 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 1 |
2 | |||||
| buildForm | |
0.00% |
0 / 5 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 1 |
6 | |||||
| listViewPanels | |
0.00% |
0 / 4 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 1 |
2 | |||||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Drupal\display_builder_ui; |
| 6 | |
| 7 | use Drupal\Core\Config\Entity\DraggableListBuilder; |
| 8 | use Drupal\Core\Entity\EntityInterface; |
| 9 | use Drupal\Core\Entity\EntityStorageInterface; |
| 10 | use Drupal\Core\Entity\EntityTypeInterface; |
| 11 | use Drupal\Core\Form\FormStateInterface; |
| 12 | use Drupal\Core\Render\Element; |
| 13 | use Drupal\Core\StringTranslation\TranslatableMarkup; |
| 14 | use Drupal\display_builder\IslandPluginManagerInterface; |
| 15 | use Drupal\display_builder\ProfileInterface; |
| 16 | use Symfony\Component\DependencyInjection\ContainerInterface; |
| 17 | |
| 18 | /** |
| 19 | * Provides a listing of Display Builder profiles. |
| 20 | */ |
| 21 | final class ProfileListBuilder extends DraggableListBuilder { |
| 22 | |
| 23 | /** |
| 24 | * The island plugin manager. |
| 25 | */ |
| 26 | protected IslandPluginManagerInterface $islandManager; |
| 27 | |
| 28 | /** |
| 29 | * {@inheritdoc} |
| 30 | */ |
| 31 | public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, IslandPluginManagerInterface $island_manager) { |
| 32 | parent::__construct($entity_type, $storage); |
| 33 | $this->islandManager = $island_manager; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * {@inheritdoc} |
| 38 | */ |
| 39 | public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type): self { |
| 40 | return new self( |
| 41 | $entity_type, |
| 42 | $container->get('entity_type.manager')->getStorage($entity_type->id()), |
| 43 | $container->get('plugin.manager.db_island'), |
| 44 | ); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * {@inheritdoc} |
| 49 | */ |
| 50 | public function getFormId(): string { |
| 51 | return 'display_builder_list_builder'; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * {@inheritdoc} |
| 56 | */ |
| 57 | public function buildHeader(): array { |
| 58 | $header = []; |
| 59 | $header['label'] = $this->t('Label'); |
| 60 | $header['description'] = $this->t('Description'); |
| 61 | $header['roles'] = $this->t('Roles'); |
| 62 | $header['status'] = $this->t('Status'); |
| 63 | |
| 64 | return $header + parent::buildHeader(); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * {@inheritdoc} |
| 69 | */ |
| 70 | public function buildRow(EntityInterface $entity): array { |
| 71 | $row = []; |
| 72 | /** @var \Drupal\display_builder\ProfileInterface $entity */ |
| 73 | $row['label'] = $entity->label(); |
| 74 | // List enabled view panels instead of showing an empty description. |
| 75 | $description = $entity->get('description') ?: $this->listViewPanels($entity); |
| 76 | $row['description']['data']['#plain_text'] = $description; |
| 77 | $row['roles']['data'] = [ |
| 78 | '#theme' => 'item_list', |
| 79 | '#items' => $entity->getRoles(), |
| 80 | '#empty' => $this->t('No roles may use this display builder'), |
| 81 | '#context' => ['list_style' => 'comma-list'], |
| 82 | ]; |
| 83 | $row['status']['data']['#plain_text'] = $entity->status() ? $this->t('Enabled') : $this->t('Disabled'); |
| 84 | |
| 85 | return $row + parent::buildRow($entity); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * {@inheritdoc} |
| 90 | */ |
| 91 | public function render(): array { |
| 92 | $build = parent::render(); |
| 93 | $build['notice'] = [ |
| 94 | '#markup' => $this->t('Profiles define the display building experience (available features, layout arrangement) for specific user roles.'), |
| 95 | '#weight' => -100, |
| 96 | ]; |
| 97 | |
| 98 | return $build; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * {@inheritdoc} |
| 103 | */ |
| 104 | public function buildForm(array $form, FormStateInterface $form_state) { |
| 105 | $form = parent::buildForm($form, $form_state); |
| 106 | $rows = Element::children($form['entities']); |
| 107 | |
| 108 | if (\count($rows) < 2) { |
| 109 | unset($form['actions']['submit']); |
| 110 | } |
| 111 | |
| 112 | return $form; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * List enabled view panels as a description fallback. |
| 117 | * |
| 118 | * @param \Drupal\display_builder\ProfileInterface $entity |
| 119 | * The entity. |
| 120 | * |
| 121 | * @return \Drupal\Core\StringTranslation\TranslatableMarkup |
| 122 | * The description listing the panels. |
| 123 | */ |
| 124 | protected function listViewPanels(ProfileInterface $entity): TranslatableMarkup { |
| 125 | $view_panels = $this->islandManager->getIslandsByTypes()['view']; |
| 126 | $view_panels = \array_intersect_key($view_panels, $entity->getEnabledIslands()); |
| 127 | $view_panels = \array_map(static fn ($island) => $island->label(), $view_panels); |
| 128 | |
| 129 | return $this->t('With: @panels', ['@panels' => \implode(', ', $view_panels)]); |
| 130 | } |
| 131 | |
| 132 | } |
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.