PageListBuilder.php in Page Manager 8.4
File
page_manager_ui/src/Entity/PageListBuilder.php
View source
<?php
namespace Drupal\page_manager_ui\Entity;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;
use Drupal\page_manager\PageInterface;
class PageListBuilder extends ConfigEntityListBuilder {
public function buildHeader() {
$header['label'] = $this
->t('Label');
$header['id'] = $this
->t('Machine name');
$header['path'] = $this
->t('Path');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity
->label();
$row['id'] = $entity
->id();
$row['path'] = $this
->getPath($entity);
return $row + parent::buildRow($entity);
}
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
$operations['edit']['url'] = new Url('entity.page.edit_form', [
'machine_name' => $entity
->id(),
'step' => 'general',
]);
return $operations;
}
protected function getPath(PageInterface $entity) {
$path = $entity
->getPath();
if ($entity
->status() && strpos($path, '%') === FALSE) {
return [
'data' => [
'#type' => 'link',
'#url' => Url::fromUserInput(rtrim($path, '/')),
'#title' => $path,
],
];
}
else {
return $path;
}
}
public function render() {
$build = parent::render();
$build['table']['#empty'] = $this
->t('There are currently no pages. <a href=":url">Add a new page.</a>', [
':url' => Url::fromRoute('entity.page.add_form')
->toString(),
]);
return $build;
}
}