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