Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
0.00% |
0 / 64 |
|
0.00% |
0 / 19 |
|
0.00% |
0 / 12 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| ViewsManagementController | |
0.00% |
0 / 64 |
|
0.00% |
0 / 19 |
|
0.00% |
0 / 12 |
|
0.00% |
0 / 4 |
110 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| pageViewsIndex | |
0.00% |
0 / 19 |
|
0.00% |
0 / 6 |
|
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| buildRow | |
0.00% |
0 / 29 |
|
0.00% |
0 / 11 |
|
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
30 | |||
| getOperationLinks | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Drupal\display_builder_views\Controller; |
| 6 | |
| 7 | use Drupal\Core\Controller\ControllerBase; |
| 8 | use Drupal\Core\Datetime\DateFormatterInterface; |
| 9 | use Drupal\Core\Url; |
| 10 | use Drupal\display_builder\ConfigFormBuilderInterface; |
| 11 | use Drupal\display_builder\DisplayBuilderHelpers; |
| 12 | use Drupal\display_builder_views\Plugin\views\display_extender\DisplayExtender; |
| 13 | |
| 14 | /** |
| 15 | * Returns responses for Display Builder ui routes. |
| 16 | */ |
| 17 | class ViewsManagementController extends ControllerBase { |
| 18 | |
| 19 | public function __construct( |
| 20 | private readonly DateFormatterInterface $dateFormatter, |
| 21 | ) {} |
| 22 | |
| 23 | /** |
| 24 | * Generate a simple index of saved display builder. |
| 25 | * |
| 26 | * @return array |
| 27 | * A render array. |
| 28 | */ |
| 29 | public function pageViewsIndex(): array { |
| 30 | $build = []; |
| 31 | $build['display_builder_table'] = [ |
| 32 | '#theme' => 'table', |
| 33 | '#header' => [ |
| 34 | 'id' => ['data' => $this->t('View')], |
| 35 | 'profile_id' => ['data' => $this->t('Profile')], |
| 36 | 'updated' => ['data' => $this->t('Updated')], |
| 37 | 'log' => ['data' => $this->t('Last log')], |
| 38 | 'operations' => ['data' => $this->t('Operations')], |
| 39 | ], |
| 40 | '#empty' => $this->t('No Display builder enabled on any view.'), |
| 41 | ]; |
| 42 | |
| 43 | $storage = $this->entityTypeManager()->getStorage('display_builder_instance'); |
| 44 | |
| 45 | foreach (\array_keys($storage->loadMultiple()) as $builder_id) { |
| 46 | if (!DisplayExtender::checkInstanceId($builder_id)) { |
| 47 | continue; |
| 48 | } |
| 49 | $build['display_builder_table']['#rows'][$builder_id] = $this->buildRow($builder_id); |
| 50 | } |
| 51 | $build['pager'] = ['#type' => 'pager']; |
| 52 | |
| 53 | return $build; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Builds a table row for a display builder related to a view display managed. |
| 58 | * |
| 59 | * @param string $builder_id |
| 60 | * The builder id. |
| 61 | * |
| 62 | * @return array |
| 63 | * A table row. |
| 64 | */ |
| 65 | protected function buildRow(string $builder_id): array { |
| 66 | $view_id = DisplayExtender::checkInstanceId($builder_id)['view']; |
| 67 | $display_id = DisplayExtender::checkInstanceId($builder_id)['display']; |
| 68 | $view = $this->entityTypeManager()->getStorage('view')->load($view_id); |
| 69 | |
| 70 | if (!$view) { |
| 71 | return []; |
| 72 | } |
| 73 | |
| 74 | $storage = $this->entityTypeManager()->getStorage('display_builder_instance'); |
| 75 | /** @var \Drupal\display_builder\InstanceInterface $builder */ |
| 76 | $builder = $storage->load($builder_id); |
| 77 | |
| 78 | if (!$builder) { |
| 79 | return []; |
| 80 | } |
| 81 | $builder = $builder->toArray(); |
| 82 | |
| 83 | $row = []; |
| 84 | |
| 85 | $row['id']['data'] = [ |
| 86 | '#type' => 'link', |
| 87 | '#title' => $view->label() . ' (' . $display_id . ')', |
| 88 | '#url' => Url::fromRoute('entity.view.edit_display_form', ['view' => $view_id, 'display_id' => $display_id]), |
| 89 | ]; |
| 90 | |
| 91 | $row['profile_id'] = [ |
| 92 | 'data-profile-id' => \sprintf('profile_%s', $view_id), |
| 93 | 'data' => $view->getDisplay($display_id)['display_options']['display_extenders']['display_builder'][ConfigFormBuilderInterface::PROFILE_PROPERTY] ?? '?', |
| 94 | ]; |
| 95 | $row['updated']['data'] = $builder['present']->time ? DisplayBuilderHelpers::formatTime($this->dateFormatter, (int) $builder['present']->time) : '-'; |
| 96 | |
| 97 | if (isset($builder['present']->log)) { |
| 98 | $row['log']['data'] = $builder['present']->log; |
| 99 | } |
| 100 | else { |
| 101 | $row['log']['data'] = '-'; |
| 102 | } |
| 103 | $row['operations']['data']['operations'] = [ |
| 104 | '#type' => 'operations', |
| 105 | '#links' => $this->getOperationLinks($builder_id), |
| 106 | ]; |
| 107 | |
| 108 | return ['data' => $row]; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Delete a display builder. |
| 113 | * |
| 114 | * @param string $builder_id |
| 115 | * The display builder id. |
| 116 | * |
| 117 | * @return array |
| 118 | * The operation links. |
| 119 | */ |
| 120 | private function getOperationLinks(string $builder_id): array { |
| 121 | return [ |
| 122 | 'manage' => [ |
| 123 | 'title' => $this->t('Build display'), |
| 124 | 'url' => DisplayExtender::getUrlFromInstanceId($builder_id), |
| 125 | 'attributes' => [ |
| 126 | 'data-link-builder' => $builder_id, |
| 127 | ], |
| 128 | ], |
| 129 | 'delete' => [ |
| 130 | 'title' => $this->t('Delete'), |
| 131 | 'url' => Url::fromRoute('display_builder_views.views.delete', [ |
| 132 | 'builder_id' => $builder_id, |
| 133 | ]), |
| 134 | ], |
| 135 | ]; |
| 136 | } |
| 137 | |
| 138 | } |
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.
| 19 | public function __construct( |
| 20 | private readonly DateFormatterInterface $dateFormatter, |
| 21 | ) {} |
| 65 | protected function buildRow(string $builder_id): array { |
| 66 | $view_id = DisplayExtender::checkInstanceId($builder_id)['view']; |
| 67 | $display_id = DisplayExtender::checkInstanceId($builder_id)['display']; |
| 68 | $view = $this->entityTypeManager()->getStorage('view')->load($view_id); |
| 69 | |
| 70 | if (!$view) { |
| 71 | return []; |
| 74 | $storage = $this->entityTypeManager()->getStorage('display_builder_instance'); |
| 75 | /** @var \Drupal\display_builder\InstanceInterface $builder */ |
| 76 | $builder = $storage->load($builder_id); |
| 77 | |
| 78 | if (!$builder) { |
| 79 | return []; |
| 81 | $builder = $builder->toArray(); |
| 82 | |
| 83 | $row = []; |
| 84 | |
| 85 | $row['id']['data'] = [ |
| 86 | '#type' => 'link', |
| 87 | '#title' => $view->label() . ' (' . $display_id . ')', |
| 88 | '#url' => Url::fromRoute('entity.view.edit_display_form', ['view' => $view_id, 'display_id' => $display_id]), |
| 89 | ]; |
| 90 | |
| 91 | $row['profile_id'] = [ |
| 92 | 'data-profile-id' => \sprintf('profile_%s', $view_id), |
| 93 | 'data' => $view->getDisplay($display_id)['display_options']['display_extenders']['display_builder'][ConfigFormBuilderInterface::PROFILE_PROPERTY] ?? '?', |
| 94 | ]; |
| 95 | $row['updated']['data'] = $builder['present']->time ? DisplayBuilderHelpers::formatTime($this->dateFormatter, (int) $builder['present']->time) : '-'; |
| 95 | $row['updated']['data'] = $builder['present']->time ? DisplayBuilderHelpers::formatTime($this->dateFormatter, (int) $builder['present']->time) : '-'; |
| 95 | $row['updated']['data'] = $builder['present']->time ? DisplayBuilderHelpers::formatTime($this->dateFormatter, (int) $builder['present']->time) : '-'; |
| 95 | $row['updated']['data'] = $builder['present']->time ? DisplayBuilderHelpers::formatTime($this->dateFormatter, (int) $builder['present']->time) : '-'; |
| 96 | |
| 97 | if (isset($builder['present']->log)) { |
| 97 | if (isset($builder['present']->log)) { |
| 98 | $row['log']['data'] = $builder['present']->log; |
| 101 | $row['log']['data'] = '-'; |
| 102 | } |
| 103 | $row['operations']['data']['operations'] = [ |
| 104 | '#type' => 'operations', |
| 104 | '#type' => 'operations', |
| 105 | '#links' => $this->getOperationLinks($builder_id), |
| 106 | ]; |
| 107 | |
| 108 | return ['data' => $row]; |
| 120 | private function getOperationLinks(string $builder_id): array { |
| 121 | return [ |
| 122 | 'manage' => [ |
| 123 | 'title' => $this->t('Build display'), |
| 124 | 'url' => DisplayExtender::getUrlFromInstanceId($builder_id), |
| 125 | 'attributes' => [ |
| 126 | 'data-link-builder' => $builder_id, |
| 127 | ], |
| 128 | ], |
| 129 | 'delete' => [ |
| 130 | 'title' => $this->t('Delete'), |
| 131 | 'url' => Url::fromRoute('display_builder_views.views.delete', [ |
| 132 | 'builder_id' => $builder_id, |
| 30 | $build = []; |
| 31 | $build['display_builder_table'] = [ |
| 32 | '#theme' => 'table', |
| 33 | '#header' => [ |
| 34 | 'id' => ['data' => $this->t('View')], |
| 35 | 'profile_id' => ['data' => $this->t('Profile')], |
| 36 | 'updated' => ['data' => $this->t('Updated')], |
| 37 | 'log' => ['data' => $this->t('Last log')], |
| 38 | 'operations' => ['data' => $this->t('Operations')], |
| 39 | ], |
| 40 | '#empty' => $this->t('No Display builder enabled on any view.'), |
| 41 | ]; |
| 42 | |
| 43 | $storage = $this->entityTypeManager()->getStorage('display_builder_instance'); |
| 44 | |
| 45 | foreach (\array_keys($storage->loadMultiple()) as $builder_id) { |
| 45 | foreach (\array_keys($storage->loadMultiple()) as $builder_id) { |
| 46 | if (!DisplayExtender::checkInstanceId($builder_id)) { |
| 47 | continue; |
| 45 | foreach (\array_keys($storage->loadMultiple()) as $builder_id) { |
| 46 | if (!DisplayExtender::checkInstanceId($builder_id)) { |
| 47 | continue; |
| 48 | } |
| 49 | $build['display_builder_table']['#rows'][$builder_id] = $this->buildRow($builder_id); |
| 45 | foreach (\array_keys($storage->loadMultiple()) as $builder_id) { |
| 46 | if (!DisplayExtender::checkInstanceId($builder_id)) { |
| 47 | continue; |
| 48 | } |
| 49 | $build['display_builder_table']['#rows'][$builder_id] = $this->buildRow($builder_id); |
| 50 | } |
| 51 | $build['pager'] = ['#type' => 'pager']; |
| 52 | |
| 53 | return $build; |