Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / config_translation / src / Controller / ConfigTranslationBlockListBuilder.php
1 <?php
2
3 namespace Drupal\config_translation\Controller;
4
5 use Drupal\Core\Entity\EntityInterface;
6 use Drupal\Core\Entity\EntityStorageInterface;
7 use Drupal\Core\Entity\EntityTypeInterface;
8 use Drupal\Core\Extension\ThemeHandlerInterface;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
10
11 /**
12  * Defines the config translation list builder for blocks.
13  */
14 class ConfigTranslationBlockListBuilder extends ConfigTranslationEntityListBuilder {
15
16   /**
17    * An array of theme info keyed by theme name.
18    *
19    * @var array
20    */
21   protected $themes = [];
22
23   /**
24    * {@inheritdoc}
25    */
26   public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ThemeHandlerInterface $theme_handler) {
27     parent::__construct($entity_type, $storage);
28     $this->themes = $theme_handler->listInfo();
29   }
30
31   /**
32    * {@inheritdoc}
33    */
34   public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
35     return new static(
36       $entity_type,
37       $container->get('entity.manager')->getStorage($entity_type->id()),
38       $container->get('theme_handler')
39     );
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   public function getFilterLabels() {
46     $info = parent::getFilterLabels();
47
48     $info['placeholder'] = $this->t('Enter block, theme or category');
49     $info['description'] = $this->t('Enter a part of the block, theme or category to filter by.');
50
51     return $info;
52   }
53
54   /**
55    * {@inheritdoc}
56    */
57   public function buildRow(EntityInterface $entity) {
58     $theme = $entity->getTheme();
59     $plugin_definition = $entity->getPlugin()->getPluginDefinition();
60
61     $row['label'] = [
62       'data' => $entity->label(),
63       'class' => 'table-filter-text-source',
64     ];
65
66     $row['theme'] = [
67       'data' => $this->themes[$theme]->info['name'],
68       'class' => 'table-filter-text-source',
69     ];
70
71     $row['category'] = [
72       'data' => $plugin_definition['category'],
73       'class' => 'table-filter-text-source',
74     ];
75
76     $row['operations']['data'] = $this->buildOperations($entity);
77
78     return $row;
79   }
80
81   /**
82    * {@inheritdoc}
83    */
84   public function buildHeader() {
85     $header['label'] = $this->t('Block');
86     $header['theme'] = $this->t('Theme');
87     $header['category'] = $this->t('Category');
88     $header['operations'] = $this->t('Operations');
89     return $header;
90   }
91
92   /**
93    * {@inheritdoc}
94    */
95   public function sortRows($a, $b) {
96     return $this->sortRowsMultiple($a, $b, ['theme', 'category', 'label']);
97   }
98
99 }