Skip to content
Snippets Groups Projects
Select Git revision
  • d663924e9344bd68a78f53ad7755aa87f69d4dbe
  • 11.x default protected
  • 11.2.x protected
  • 10.5.x protected
  • 10.6.x protected
  • 11.1.x protected
  • 10.4.x protected
  • 11.0.x protected
  • 10.3.x protected
  • 7.x protected
  • 10.2.x protected
  • 10.1.x protected
  • 9.5.x protected
  • 10.0.x protected
  • 9.4.x protected
  • 9.3.x protected
  • 9.2.x protected
  • 9.1.x protected
  • 8.9.x protected
  • 9.0.x protected
  • 8.8.x protected
  • 10.5.1 protected
  • 11.2.2 protected
  • 11.2.1 protected
  • 11.2.0 protected
  • 10.5.0 protected
  • 11.2.0-rc2 protected
  • 10.5.0-rc1 protected
  • 11.2.0-rc1 protected
  • 10.4.8 protected
  • 11.1.8 protected
  • 10.5.0-beta1 protected
  • 11.2.0-beta1 protected
  • 11.2.0-alpha1 protected
  • 10.4.7 protected
  • 11.1.7 protected
  • 10.4.6 protected
  • 11.1.6 protected
  • 10.3.14 protected
  • 10.4.5 protected
  • 11.0.13 protected
41 results

DateFormatListController.php

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    DateFormatListController.php 2.49 KiB
    <?php
    
    /**
     * @file
     * Contains \Drupal\system\DateFormatListController.
     */
    
    namespace Drupal\system;
    
    use Drupal\Component\Utility\String;
    use Drupal\Core\Config\Entity\ConfigEntityListController;
    use Drupal\Core\Datetime\Date;
    use Drupal\Core\Entity\EntityInterface;
    use Drupal\Core\Entity\EntityStorageControllerInterface;
    use Drupal\Core\Extension\ModuleHandlerInterface;
    use Symfony\Component\DependencyInjection\ContainerInterface;
    
    /**
     * Provides a listing of date formats.
     */
    class DateFormatListController extends ConfigEntityListController {
    
      /**
       * The date service.
       *
       * @var \Drupal\Core\Datetime\Date
       */
      protected $dateService;
    
      /**
       * Constructs a new DateFormatListController object.
       *
       * @param string $entity_type
       *   The type of entity to be listed.
       * @param array $entity_info
       *   An array of entity info for the entity type.
       * @param \Drupal\Core\Entity\EntityStorageControllerInterface $storage
       *   The entity storage controller class.
       * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
       *   The module handler to invoke hooks on.
       * @param \Drupal\Core\Datetime\Date $date_service
       *   The date service.
       */
      public function __construct($entity_type, array $entity_info, EntityStorageControllerInterface $storage, ModuleHandlerInterface $module_handler, Date $date_service) {
        parent::__construct($entity_type, $entity_info, $storage, $module_handler);
    
        $this->dateService = $date_service;
      }
    
      /**
       * {@inheritdoc}
       */
      public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) {
        return new static(
          $entity_type,
          $entity_info,
          $container->get('plugin.manager.entity')->getStorageController($entity_type),
          $container->get('module_handler'),
          $container->get('date')
        );
      }
    
      /**
       * {@inheritdoc}
       */
      public function load() {
        return array_filter(parent::load(), function ($entity) {
          return !$entity->isLocked();
        });
      }
    
      /**
       * {@inheritdoc}
       */
      public function buildHeader() {
        $header['id'] = t('Machine name');
        $header['label'] = t('Name');
        $header['pattern'] = t('Pattern');
        return $header + parent::buildHeader();
      }
    
      /**
       * {@inheritdoc}
       */
      public function buildRow(EntityInterface $entity) {
        $row['id'] = $entity->id();
        $row['label'] = $this->getLabel($entity);
        $row['pattern'] = $this->dateService->format(REQUEST_TIME, $entity->id());
        return $row + parent::buildRow($entity);
      }
    
    }