You are here

public function CustomPublishingOptionListBuilder::render in Custom Publishing Options 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/CustomPublishingOptionListBuilder.php, line 34

Class

CustomPublishingOptionListBuilder
Provides a listing of Custom publishing option entities.

Namespace

Drupal\custom_pub

Code

public function render() {
  $build['table'] = [
    '#type' => 'table',
    '#header' => $this
      ->buildHeader(),
    '#title' => $this
      ->getTitle(),
    '#rows' => [],
    '#empty' => $this
      ->t('There are no @label defined yet.', [
      '@label' => 'custom publishing options',
    ]),
    '#cache' => [
      'contexts' => $this->entityType
        ->getListCacheContexts(),
      'tags' => $this->entityType
        ->getListCacheTags(),
    ],
  ];
  foreach ($this
    ->load() as $entity) {
    if ($row = $this
      ->buildRow($entity)) {
      $build['table']['#rows'][$entity
        ->id()] = $row;
    }
  }

  // Only add the pager if a limit is specified.
  if ($this->limit) {
    $build['pager'] = [
      '#type' => 'pager',
    ];
  }
  return $build;
}