class DateFormatListBuilder

Same name and namespace in other branches
  1. 11.x core/modules/system/src/DateFormatListBuilder.php \Drupal\system\DateFormatListBuilder
  2. 10 core/modules/system/src/DateFormatListBuilder.php \Drupal\system\DateFormatListBuilder
  3. 9 core/modules/system/src/DateFormatListBuilder.php \Drupal\system\DateFormatListBuilder
  4. 8.9.x core/modules/system/src/DateFormatListBuilder.php \Drupal\system\DateFormatListBuilder

Defines a class to build a listing of date format entities.

Hierarchy

Expanded class hierarchy of DateFormatListBuilder

See also

\Drupal\system\Entity\DateFormat

File

core/modules/system/src/DateFormatListBuilder.php, line 19

Namespace

Drupal\system
View source
class DateFormatListBuilder extends ConfigEntityListBuilder {
  use StringTranslationTrait;
  
  /**
   * Constructs a new DateFormatListBuilder object.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
   *   The entity type definition.
   * @param \Drupal\Core\Entity\EntityStorageInterface $storage
   *   The entity storage class.
   * @param \Drupal\Core\Datetime\DateFormatterInterface $dateFormatter
   *   The date formatter service.
   * @param \Drupal\Component\Datetime\TimeInterface $time
   *   The time service.
   */
  public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, protected DateFormatterInterface $dateFormatter, protected TimeInterface $time) {
    parent::__construct($entity_type, $storage);
  }
  
  /**
   * {@inheritdoc}
   */
  public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
    return new static($entity_type, $container->get('entity_type.manager')
      ->getStorage($entity_type->id()), $container->get('date.formatter'), $container->get('datetime.time'));
  }
  
  /**
   * {@inheritdoc}
   */
  public function buildHeader() {
    $header['label'] = $this->t('Name');
    $header['pattern'] = $this->t('Pattern');
    return $header + parent::buildHeader();
  }
  
  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {
    $row['label'] = $entity->label();
    $row['pattern'] = $this->dateFormatter
      ->format($this->time
      ->getRequestTime(), $entity->id());
    return $row + parent::buildRow($entity);
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.