e8375d13c794a191a5ea29b3b34176c16d3ed684
[yaffs-website] / src / EnvironmentIndicatorListBuilder.php
1 <?php
2
3 namespace Drupal\environment_indicator;
4
5 use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
6 use Drupal\Core\Entity\EntityInterface;
7 use Drupal\Core\Url;
8
9 /**
10  * Provides a listing of environments.
11  */
12 class EnvironmentIndicatorListBuilder extends ConfigEntityListBuilder {
13
14   /**
15    * {@inheritdoc}
16    */
17   public function getFormID() {
18     return 'environment_indicator_overview_environments';
19   }
20
21   /**
22    * {@inheritdoc}
23    */
24   public function buildHeader() {
25     $row['name'] = $this->t('Environment name');
26     $row['url'] = $this->t('Environment url');
27     $row += parent::buildHeader();
28     return $row;
29   }
30
31   /**
32    * {@inheritdoc}
33    */
34   public function buildRow(EntityInterface $entity) {
35     /* @var \Drupal\environment_indicator\Entity\EnvironmentIndicator $entity */
36     $row = [
37       'style' => 'color: ' . $entity->getFgColor() . '; background-color: ' . $entity->getBgColor() . ';',
38     ];
39
40     $row['data']['name'] = [
41       'data' => $entity->label(),
42     ];
43     $row['data']['url'] = [
44       'data' => $entity->getUrl(),
45     ];
46
47     $row['data'] += parent::buildRow($entity);
48     return $row;
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   public function render() {
55     $build['action_header']['#markup'] = '<h3>' . $this->t('Available actions:') . '</h3>';
56     $entities = $this->load();
57     // If there are not multiple vocabularies, disable dragging by unsetting the
58     // weight key.
59     if (count($entities) <= 1) {
60       unset($this->weightKey);
61     }
62     $build = parent::render();
63     $build['table']['#empty'] = $this->t('No environment switchers available. <a href=":link">Add environment</a>.', [':link' => Url::fromRoute('entity.environment_indicator.add')->toString()]);
64     return $build;
65   }
66
67 }