You are here

DashboardListBuilder.php in Dashboards with Layout Builder 8

Same filename and directory in other branches
  1. 2.0.x src/Entity/DashboardListBuilder.php

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.
 *
 * @package Drupal\dashboards\Entity
 */
class DashboardListBuilder extends DraggableListBuilder {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'dashboards';
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  public function buildHeader() {
    $header = [
      $this
        ->t('Admin Label'),
      $this
        ->t('Category'),
    ];
    return $header + parent::buildHeader();
  }

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {
    $row = [];
    $row['label'] = $entity
      ->label();
    $row['category']['#markup'] = $entity->category;
    return $row + parent::buildRow($entity);
  }

}

Classes

Namesort descending Description
DashboardListBuilder Class DashboardListBuilder.