You are here

public function EntityQueueListBuilder::render in Entityqueue 8

Builds the entity listing as renderable array for table.html.twig.

@todo Add a link to add a new item to the #empty text.

Overrides EntityListBuilder::render

File

src/EntityQueueListBuilder.php, line 111

Class

EntityQueueListBuilder
Defines a class that builds a listing of entity queues.

Namespace

Drupal\entityqueue

Code

public function render() {
  $entities = $this
    ->load();
  $build['#type'] = 'container';
  $build['#attributes']['id'] = 'entity-queue-list';
  $build['#attached']['library'][] = 'core/drupal.ajax';
  $build['#cache'] = [
    'contexts' => Cache::mergeContexts($this->entityType
      ->getListCacheContexts(), [
      'user.permissions',
    ]),
    'tags' => $this->entityType
      ->getListCacheTags(),
  ];
  $build['enabled']['heading']['#markup'] = '<h2>' . $this
    ->t('Enabled', [], [
    'context' => 'Plural',
  ]) . '</h2>';
  $build['disabled']['heading']['#markup'] = '<h2>' . $this
    ->t('Disabled', [], [
    'context' => 'Plural',
  ]) . '</h2>';
  foreach ([
    'enabled',
    'disabled',
  ] as $status) {
    $build[$status]['#type'] = 'container';
    $build[$status]['#attributes'] = [
      'class' => [
        'entity-queue-list-section',
        $status,
      ],
    ];
    $build[$status]['table'] = [
      '#type' => 'table',
      '#attributes' => [
        'class' => [
          'entity-queue-listing-table',
        ],
      ],
      '#header' => $this
        ->buildHeader(),
      '#rows' => [],
      '#cache' => [
        'contexts' => $this->entityType
          ->getListCacheContexts(),
        'tags' => $this->entityType
          ->getListCacheTags(),
      ],
    ];
    foreach ($entities[$status] as $entity) {
      $build[$status]['table']['#rows'][$entity
        ->id()] = $this
        ->buildRow($entity);
    }
  }

  // @todo Use a placeholder for the entity label if this is abstracted to
  //   other entity types.
  $build['enabled']['table']['#empty'] = $this
    ->t('There are no enabled queues.');
  $build['disabled']['table']['#empty'] = $this
    ->t('There are no disabled queues.');
  return $build;
}