CustomPublishingOptionListBuilder.php in Custom Publishing Options 8
File
src/CustomPublishingOptionListBuilder.php
View source
<?php
namespace Drupal\custom_pub;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
class CustomPublishingOptionListBuilder extends ConfigEntityListBuilder {
public function buildHeader() {
$header['label'] = $this
->t('Custom publishing option');
$header['id'] = $this
->t('Machine name');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity
->label();
$row['id'] = $entity
->id();
return $row + parent::buildRow($entity);
}
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;
}
}
if ($this->limit) {
$build['pager'] = [
'#type' => 'pager',
];
}
return $build;
}
}