Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
0.00% |
0 / 59 |
|
0.00% |
0 / 14 |
|
0.00% |
0 / 9 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| ViewsManagementController | |
0.00% |
0 / 59 |
|
0.00% |
0 / 14 |
|
0.00% |
0 / 9 |
|
0.00% |
0 / 4 |
72 | |
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 / 16 |
|
0.00% |
0 / 4 |
|
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| buildRow | |
0.00% |
0 / 27 |
|
0.00% |
0 / 8 |
|
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
20 | |||
| 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\DisplayBuildableInterface; |
| 11 | use Drupal\display_builder\DisplayBuilderHelpers; |
| 12 | use Drupal\display_builder\InstanceInterface; |
| 13 | use Drupal\display_builder_views\Plugin\display_builder\Buildable\ViewDisplay; |
| 14 | |
| 15 | /** |
| 16 | * Returns responses for Display Builder ui routes. |
| 17 | */ |
| 18 | class ViewsManagementController extends ControllerBase { |
| 19 | |
| 20 | public function __construct( |
| 21 | protected DateFormatterInterface $dateFormatter, |
| 22 | ) {} |
| 23 | |
| 24 | /** |
| 25 | * Generate a simple index of saved display builder. |
| 26 | * |
| 27 | * @return array |
| 28 | * A render array. |
| 29 | */ |
| 30 | public function pageViewsIndex(): array { |
| 31 | $build = []; |
| 32 | $build['display_builder_table'] = [ |
| 33 | '#theme' => 'table', |
| 34 | '#header' => [ |
| 35 | 'id' => ['data' => $this->t('View')], |
| 36 | 'profile_id' => ['data' => $this->t('Profile')], |
| 37 | 'updated' => ['data' => $this->t('Updated')], |
| 38 | 'log' => ['data' => $this->t('Last log')], |
| 39 | 'operations' => ['data' => $this->t('Operations')], |
| 40 | ], |
| 41 | '#empty' => $this->t('No Display builder enabled on any view.'), |
| 42 | ]; |
| 43 | |
| 44 | foreach (ViewDisplay::collectInstances() as $instance_id => $instance) { |
| 45 | $build['display_builder_table']['#rows'][$instance_id] = $this->buildRow($instance); |
| 46 | } |
| 47 | $build['pager'] = ['#type' => 'pager']; |
| 48 | |
| 49 | return $build; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Builds a table row for a display builder related to a view display managed. |
| 54 | * |
| 55 | * @param \Drupal\display_builder\InstanceInterface|null $instance |
| 56 | * The display builder instance (or NULL). |
| 57 | * |
| 58 | * @return array |
| 59 | * A table row. |
| 60 | */ |
| 61 | protected function buildRow(?InstanceInterface $instance): array { |
| 62 | if (!$instance) { |
| 63 | return []; |
| 64 | } |
| 65 | |
| 66 | $instance_id = (string) $instance->id(); |
| 67 | $view_id = ViewDisplay::checkInstanceId($instance_id)['view']; |
| 68 | $display_id = ViewDisplay::checkInstanceId($instance_id)['display']; |
| 69 | $view = $this->entityTypeManager()->getStorage('view')->load($view_id); |
| 70 | |
| 71 | if (!$view) { |
| 72 | return []; |
| 73 | } |
| 74 | |
| 75 | $row = []; |
| 76 | |
| 77 | $row['id']['data'] = [ |
| 78 | '#type' => 'link', |
| 79 | '#title' => $view->label() . ' (' . $display_id . ')', |
| 80 | '#url' => Url::fromRoute('entity.view.edit_display_form', ['view' => $view_id, 'display_id' => $display_id]), |
| 81 | ]; |
| 82 | |
| 83 | $row['profile_id'] = [ |
| 84 | 'data-profile-id' => \sprintf('profile_%s', $view_id), |
| 85 | 'data' => $view->getDisplay($display_id)['display_options']['display_extenders']['display_builder'][DisplayBuildableInterface::PROFILE_PROPERTY] ?? '?', |
| 86 | ]; |
| 87 | $row['updated']['data'] = DisplayBuilderHelpers::formatTime($this->dateFormatter, (int) $instance->getRevisionCreationTime()); |
| 88 | |
| 89 | if ($log = $instance->getRevisionLogMessage()) { |
| 90 | $row['log']['data'] = $log; |
| 91 | } |
| 92 | else { |
| 93 | $row['log']['data'] = '-'; |
| 94 | } |
| 95 | $row['operations']['data']['operations'] = [ |
| 96 | '#type' => 'operations', |
| 97 | '#links' => $this->getOperationLinks($instance_id), |
| 98 | ]; |
| 99 | |
| 100 | return ['data' => $row]; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Delete a display builder. |
| 105 | * |
| 106 | * @param string $builder_id |
| 107 | * The display builder id. |
| 108 | * |
| 109 | * @return array |
| 110 | * The operation links. |
| 111 | */ |
| 112 | private function getOperationLinks(string $builder_id): array { |
| 113 | return [ |
| 114 | 'manage' => [ |
| 115 | 'title' => $this->t('Build display'), |
| 116 | 'url' => ViewDisplay::getUrlFromInstanceId($builder_id), |
| 117 | 'attributes' => [ |
| 118 | 'data-link-builder' => $builder_id, |
| 119 | ], |
| 120 | ], |
| 121 | 'delete' => [ |
| 122 | 'title' => $this->t('Delete'), |
| 123 | 'url' => Url::fromRoute('display_builder_views.views.delete', [ |
| 124 | 'builder_id' => $builder_id, |
| 125 | ]), |
| 126 | ], |
| 127 | ]; |
| 128 | } |
| 129 | |
| 130 | } |
Below are the source code lines that represent each code path as identified by Xdebug. Please note a path is not
necessarily coterminous with a line, a line may contain multiple paths and therefore show up more than once.
Please also be aware that some paths may include implicit rather than explicit branches, e.g. an if statement
always has an else as part of its logical flow even if you didn't write one.
| 21 | protected DateFormatterInterface $dateFormatter, |
| 22 | ) {} |
| 61 | protected function buildRow(?InstanceInterface $instance): array { |
| 62 | if (!$instance) { |
| 63 | return []; |
| 61 | protected function buildRow(?InstanceInterface $instance): array { |
| 62 | if (!$instance) { |
| 66 | $instance_id = (string) $instance->id(); |
| 67 | $view_id = ViewDisplay::checkInstanceId($instance_id)['view']; |
| 68 | $display_id = ViewDisplay::checkInstanceId($instance_id)['display']; |
| 69 | $view = $this->entityTypeManager()->getStorage('view')->load($view_id); |
| 70 | |
| 71 | if (!$view) { |
| 72 | return []; |
| 61 | protected function buildRow(?InstanceInterface $instance): array { |
| 62 | if (!$instance) { |
| 66 | $instance_id = (string) $instance->id(); |
| 67 | $view_id = ViewDisplay::checkInstanceId($instance_id)['view']; |
| 68 | $display_id = ViewDisplay::checkInstanceId($instance_id)['display']; |
| 69 | $view = $this->entityTypeManager()->getStorage('view')->load($view_id); |
| 70 | |
| 71 | if (!$view) { |
| 75 | $row = []; |
| 76 | |
| 77 | $row['id']['data'] = [ |
| 78 | '#type' => 'link', |
| 79 | '#title' => $view->label() . ' (' . $display_id . ')', |
| 80 | '#url' => Url::fromRoute('entity.view.edit_display_form', ['view' => $view_id, 'display_id' => $display_id]), |
| 81 | ]; |
| 82 | |
| 83 | $row['profile_id'] = [ |
| 84 | 'data-profile-id' => \sprintf('profile_%s', $view_id), |
| 85 | 'data' => $view->getDisplay($display_id)['display_options']['display_extenders']['display_builder'][DisplayBuildableInterface::PROFILE_PROPERTY] ?? '?', |
| 86 | ]; |
| 87 | $row['updated']['data'] = DisplayBuilderHelpers::formatTime($this->dateFormatter, (int) $instance->getRevisionCreationTime()); |
| 88 | |
| 89 | if ($log = $instance->getRevisionLogMessage()) { |
| 89 | if ($log = $instance->getRevisionLogMessage()) { |
| 90 | $row['log']['data'] = $log; |
| 96 | '#type' => 'operations', |
| 97 | '#links' => $this->getOperationLinks($instance_id), |
| 98 | ]; |
| 99 | |
| 100 | return ['data' => $row]; |
| 101 | } |
| 61 | protected function buildRow(?InstanceInterface $instance): array { |
| 62 | if (!$instance) { |
| 66 | $instance_id = (string) $instance->id(); |
| 67 | $view_id = ViewDisplay::checkInstanceId($instance_id)['view']; |
| 68 | $display_id = ViewDisplay::checkInstanceId($instance_id)['display']; |
| 69 | $view = $this->entityTypeManager()->getStorage('view')->load($view_id); |
| 70 | |
| 71 | if (!$view) { |
| 75 | $row = []; |
| 76 | |
| 77 | $row['id']['data'] = [ |
| 78 | '#type' => 'link', |
| 79 | '#title' => $view->label() . ' (' . $display_id . ')', |
| 80 | '#url' => Url::fromRoute('entity.view.edit_display_form', ['view' => $view_id, 'display_id' => $display_id]), |
| 81 | ]; |
| 82 | |
| 83 | $row['profile_id'] = [ |
| 84 | 'data-profile-id' => \sprintf('profile_%s', $view_id), |
| 85 | 'data' => $view->getDisplay($display_id)['display_options']['display_extenders']['display_builder'][DisplayBuildableInterface::PROFILE_PROPERTY] ?? '?', |
| 86 | ]; |
| 87 | $row['updated']['data'] = DisplayBuilderHelpers::formatTime($this->dateFormatter, (int) $instance->getRevisionCreationTime()); |
| 88 | |
| 89 | if ($log = $instance->getRevisionLogMessage()) { |
| 93 | $row['log']['data'] = '-'; |
| 94 | } |
| 95 | $row['operations']['data']['operations'] = [ |
| 96 | '#type' => 'operations', |
| 96 | '#type' => 'operations', |
| 97 | '#links' => $this->getOperationLinks($instance_id), |
| 98 | ]; |
| 99 | |
| 100 | return ['data' => $row]; |
| 101 | } |
| 112 | private function getOperationLinks(string $builder_id): array { |
| 113 | return [ |
| 114 | 'manage' => [ |
| 115 | 'title' => $this->t('Build display'), |
| 116 | 'url' => ViewDisplay::getUrlFromInstanceId($builder_id), |
| 117 | 'attributes' => [ |
| 118 | 'data-link-builder' => $builder_id, |
| 119 | ], |
| 120 | ], |
| 121 | 'delete' => [ |
| 122 | 'title' => $this->t('Delete'), |
| 123 | 'url' => Url::fromRoute('display_builder_views.views.delete', [ |
| 124 | 'builder_id' => $builder_id, |
| 125 | ]), |
| 126 | ], |
| 127 | ]; |
| 128 | } |
| 31 | $build = []; |
| 32 | $build['display_builder_table'] = [ |
| 33 | '#theme' => 'table', |
| 34 | '#header' => [ |
| 35 | 'id' => ['data' => $this->t('View')], |
| 36 | 'profile_id' => ['data' => $this->t('Profile')], |
| 37 | 'updated' => ['data' => $this->t('Updated')], |
| 38 | 'log' => ['data' => $this->t('Last log')], |
| 39 | 'operations' => ['data' => $this->t('Operations')], |
| 40 | ], |
| 41 | '#empty' => $this->t('No Display builder enabled on any view.'), |
| 42 | ]; |
| 43 | |
| 44 | foreach (ViewDisplay::collectInstances() as $instance_id => $instance) { |
| 44 | foreach (ViewDisplay::collectInstances() as $instance_id => $instance) { |
| 44 | foreach (ViewDisplay::collectInstances() as $instance_id => $instance) { |
| 44 | foreach (ViewDisplay::collectInstances() as $instance_id => $instance) { |
| 44 | foreach (ViewDisplay::collectInstances() as $instance_id => $instance) { |
| 45 | $build['display_builder_table']['#rows'][$instance_id] = $this->buildRow($instance); |
| 46 | } |
| 47 | $build['pager'] = ['#type' => 'pager']; |
| 48 | |
| 49 | return $build; |
| 50 | } |
| 31 | $build = []; |
| 32 | $build['display_builder_table'] = [ |
| 33 | '#theme' => 'table', |
| 34 | '#header' => [ |
| 35 | 'id' => ['data' => $this->t('View')], |
| 36 | 'profile_id' => ['data' => $this->t('Profile')], |
| 37 | 'updated' => ['data' => $this->t('Updated')], |
| 38 | 'log' => ['data' => $this->t('Last log')], |
| 39 | 'operations' => ['data' => $this->t('Operations')], |
| 40 | ], |
| 41 | '#empty' => $this->t('No Display builder enabled on any view.'), |
| 42 | ]; |
| 43 | |
| 44 | foreach (ViewDisplay::collectInstances() as $instance_id => $instance) { |
| 44 | foreach (ViewDisplay::collectInstances() as $instance_id => $instance) { |
| 44 | foreach (ViewDisplay::collectInstances() as $instance_id => $instance) { |
| 45 | $build['display_builder_table']['#rows'][$instance_id] = $this->buildRow($instance); |
| 46 | } |
| 47 | $build['pager'] = ['#type' => 'pager']; |
| 48 | |
| 49 | return $build; |
| 50 | } |
| 31 | $build = []; |
| 32 | $build['display_builder_table'] = [ |
| 33 | '#theme' => 'table', |
| 34 | '#header' => [ |
| 35 | 'id' => ['data' => $this->t('View')], |
| 36 | 'profile_id' => ['data' => $this->t('Profile')], |
| 37 | 'updated' => ['data' => $this->t('Updated')], |
| 38 | 'log' => ['data' => $this->t('Last log')], |
| 39 | 'operations' => ['data' => $this->t('Operations')], |
| 40 | ], |
| 41 | '#empty' => $this->t('No Display builder enabled on any view.'), |
| 42 | ]; |
| 43 | |
| 44 | foreach (ViewDisplay::collectInstances() as $instance_id => $instance) { |
| 44 | foreach (ViewDisplay::collectInstances() as $instance_id => $instance) { |
| 45 | $build['display_builder_table']['#rows'][$instance_id] = $this->buildRow($instance); |
| 46 | } |
| 47 | $build['pager'] = ['#type' => 'pager']; |
| 48 | |
| 49 | return $build; |
| 50 | } |