Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
0.00% |
0 / 38 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
||
| InstanceListBuilder | |
0.00% |
0 / 38 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 7 |
110 | |
0.00% |
0 / 1 |
||
| __construct | |
0.00% |
0 / 1 |
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 / 8 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 1 |
2 | |||||
| render | |
0.00% |
0 / 7 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 1 |
2 | |||||
| buildRow | |
0.00% |
0 / 15 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 1 |
20 | |||||
| getEntityIds | |
0.00% |
0 / 1 |
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\Datetime\DateFormatterInterface; |
| 8 | use Drupal\Core\Entity\EntityInterface; |
| 9 | use Drupal\Core\Entity\EntityListBuilder; |
| 10 | use Drupal\Core\Entity\EntityStorageInterface; |
| 11 | use Drupal\Core\Entity\EntityTypeInterface; |
| 12 | use Drupal\display_builder\DisplayBuilderHelpers; |
| 13 | use Symfony\Component\DependencyInjection\ContainerInterface; |
| 14 | |
| 15 | /** |
| 16 | * Provides a listing of display builders instances. |
| 17 | */ |
| 18 | final class InstanceListBuilder extends EntityListBuilder { |
| 19 | |
| 20 | /** |
| 21 | * {@inheritdoc} |
| 22 | */ |
| 23 | public function __construct( |
| 24 | protected EntityTypeInterface $entity_type, |
| 25 | EntityStorageInterface $storage, |
| 26 | private readonly DateFormatterInterface $dateFormatter, |
| 27 | ) { |
| 28 | parent::__construct($entity_type, $storage); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * {@inheritdoc} |
| 33 | */ |
| 34 | public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type): self { |
| 35 | return new self( |
| 36 | $entity_type, |
| 37 | $container->get('entity_type.manager')->getStorage($entity_type->id()), |
| 38 | $container->get('date.formatter'), |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * {@inheritdoc} |
| 44 | */ |
| 45 | public function getFormId(): string { |
| 46 | return 'display_builder_instance_list_builder'; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * {@inheritdoc} |
| 51 | */ |
| 52 | public function buildHeader(): array { |
| 53 | $header = [ |
| 54 | 'id' => $this->t('Instance'), |
| 55 | 'profile' => $this->t('Profile'), |
| 56 | 'context' => $this->t('Context'), |
| 57 | 'updated' => $this->t('Updated'), |
| 58 | 'log' => $this->t('Last log'), |
| 59 | ]; |
| 60 | |
| 61 | return $header + parent::buildHeader(); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * {@inheritdoc} |
| 66 | */ |
| 67 | public function render(): array { |
| 68 | $build = parent::render(); |
| 69 | $build['notice'] = [ |
| 70 | '#markup' => '<p>' . $this->t('Instances are versions of displays (entity views, page layouts, views...) currently under work.') . ' ' |
| 71 | . $this->t('They are created automatically from the displays and must be managed from them.') . '</p>', |
| 72 | '#weight' => -100, |
| 73 | ]; |
| 74 | |
| 75 | return $build; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * {@inheritdoc} |
| 80 | */ |
| 81 | public function buildRow(EntityInterface $instance): array { |
| 82 | /** @var \Drupal\display_builder\InstanceInterface $instance */ |
| 83 | $instance_id = (string) $instance->id(); |
| 84 | $row = []; |
| 85 | |
| 86 | $type = '-'; |
| 87 | $providers = $this->moduleHandler->invokeAll('display_builder_provider_info'); |
| 88 | |
| 89 | foreach ($providers as $provider) { |
| 90 | if (\str_starts_with($instance_id, $provider['prefix'])) { |
| 91 | $type = $provider['label']; |
| 92 | |
| 93 | break; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | $row['id']['data'] = $instance_id; |
| 98 | $row['profile']['data'] = $instance->getProfile()->label(); |
| 99 | $row['context']['data'] = $type; |
| 100 | |
| 101 | /** @var \Drupal\display_builder\HistoryStep $present */ |
| 102 | $present = $instance->getCurrent(); |
| 103 | $row['updated']['data'] = $present->time ? DisplayBuilderHelpers::formatTime($this->dateFormatter, (int) $present->time) : '-'; |
| 104 | $row['log']['data'] = $present->log ?? '-'; |
| 105 | |
| 106 | return $row + parent::buildRow($instance); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * {@inheritdoc} |
| 111 | */ |
| 112 | protected function getEntityIds(): array { |
| 113 | // To avoid implementing EntityStorageInterface::getQuery() |
| 114 | return \array_keys($this->getStorage()->loadMultiple()); |
| 115 | } |
| 116 | |
| 117 | } |