Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / system / src / DateFormatListBuilder.php
1 <?php
2
3 namespace Drupal\system;
4
5 use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
6 use Drupal\Core\Datetime\DateFormatterInterface;
7 use Drupal\Core\Entity\EntityInterface;
8 use Drupal\Core\Entity\EntityStorageInterface;
9 use Drupal\Core\Entity\EntityTypeInterface;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
11
12 /**
13  * Defines a class to build a listing of date format entities.
14  *
15  * @see \Drupal\system\Entity\DateFormat
16  */
17 class DateFormatListBuilder extends ConfigEntityListBuilder {
18
19   /**
20    * The date formatter service.
21    *
22    * @var \Drupal\Core\Datetime\DateFormatterInterface
23    */
24   protected $dateFormatter;
25
26   /**
27    * Constructs a new DateFormatListBuilder object.
28    *
29    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
30    *   The entity type definition.
31    * @param \Drupal\Core\Entity\EntityStorageInterface $storage
32    *   The entity storage class.
33    * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
34    *   The date formatter service.
35    */
36   public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, DateFormatterInterface $date_formatter) {
37     parent::__construct($entity_type, $storage);
38
39     $this->dateFormatter = $date_formatter;
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
46     return new static(
47       $entity_type,
48       $container->get('entity.manager')->getStorage($entity_type->id()),
49       $container->get('date.formatter')
50     );
51   }
52
53   /**
54    * {@inheritdoc}
55    */
56   public function buildHeader() {
57     $header['label'] = t('Name');
58     $header['pattern'] = t('Pattern');
59     return $header + parent::buildHeader();
60   }
61
62   /**
63    * {@inheritdoc}
64    */
65   public function buildRow(EntityInterface $entity) {
66     $row['label'] = $entity->label();
67     $row['pattern'] = $this->dateFormatter->format(REQUEST_TIME, $entity->id());
68     return $row + parent::buildRow($entity);
69   }
70
71 }