DashboardListBuilder.php in Dashboards with Layout Builder 8
File
src/Entity/DashboardListBuilder.php
View source
<?php
namespace Drupal\dashboards\Entity;
use Drupal\Core\Url;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Config\Entity\DraggableListBuilder;
use Drupal\Core\StringTranslation\TranslatableMarkup;
class DashboardListBuilder extends DraggableListBuilder {
public function getFormId() {
return 'dashboards';
}
public function getOperations(EntityInterface $entity) {
$operations = [
'view' => [
'title' => new TranslatableMarkup('View'),
'weight' => 1,
'url' => Url::fromRoute('entity.dashboard.canonical', [
'dashboard' => $entity
->id(),
]),
],
'layout' => [
'title' => new TranslatableMarkup('Manage Layout'),
'weight' => 1,
'url' => Url::fromRoute('layout_builder.dashboards.view', [
'dashboard' => $entity
->id(),
]),
],
] + parent::getOperations($entity);
return $operations;
}
public function buildHeader() {
$header = [
$this
->t('Admin Label'),
$this
->t('Category'),
];
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row = [];
$row['label'] = $entity
->label();
$row['category']['#markup'] = $entity->category;
return $row + parent::buildRow($entity);
}
}