Newer
Older
Alex Pott
committed
<?php
/**
* @file
* Contains \Drupal\system\DateFormatListBuilder.
Alex Pott
committed
*/
namespace Drupal\system;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
Alex Pott
committed
use Drupal\Core\Datetime\DateFormatterInterface;
Alex Pott
committed
use Drupal\Core\Entity\EntityInterface;
catch
committed
use Drupal\Core\Entity\EntityStorageInterface;
Alex Pott
committed
use Drupal\Core\Entity\EntityTypeInterface;
Alex Pott
committed
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines a class to build a listing of date format entities.
*
* @see \Drupal\system\Entity\DateFormat
Alex Pott
committed
*/
class DateFormatListBuilder extends ConfigEntityListBuilder {
Alex Pott
committed
/**
* The date formatter service.
Alex Pott
committed
*
Alex Pott
committed
* @var \Drupal\Core\Datetime\DateFormatterInterface
Alex Pott
committed
*/
protected $dateFormatter;
Alex Pott
committed
/**
* Constructs a new DateFormatListBuilder object.
Alex Pott
committed
*
Alex Pott
committed
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
catch
committed
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The entity storage class.
Alex Pott
committed
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter service.
Alex Pott
committed
*/
Alex Pott
committed
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, DateFormatterInterface $date_formatter) {
Alex Pott
committed
parent::__construct($entity_type, $storage);
Alex Pott
committed
$this->dateFormatter = $date_formatter;
Alex Pott
committed
}
/**
* {@inheritdoc}
*/
Alex Pott
committed
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
Alex Pott
committed
return new static(
Alex Pott
committed
$entity_type,
catch
committed
$container->get('entity.manager')->getStorage($entity_type->id()),
Alex Pott
committed
$container->get('date.formatter')
Alex Pott
committed
);
}
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['label'] = t('Name');
$header['pattern'] = t('Pattern');
return $header + parent::buildHeader();
Alex Pott
committed
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity->label();
$row['pattern'] = $this->dateFormatter->format(REQUEST_TIME, $entity->id());
return $row + parent::buildRow($entity);