W3cubDocs

/Drupal 8

public function EntityListBuilder::render

public EntityListBuilder::render()

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 EntityListBuilderInterface::render

File

core/lib/Drupal/Core/Entity/EntityListBuilder.php, line 216

Class

EntityListBuilder
Defines a generic implementation to build a listing of entities.

Namespace

Drupal\Core\Entity

Code

public function render() {
  $build['table'] = array(
    '#type' => 'table',
    '#header' => $this->buildHeader(),
    '#title' => $this->getTitle(),
    '#rows' => array(),
    '#empty' => $this->t('There is no @label yet.', array('@label' => $this->entityType->getLabel())),
    '#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'] = array(
      '#type' => 'pager',
    );
  }
  return $build;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!EntityListBuilder.php/function/EntityListBuilder::render/8.1.x