You are here

TypeGroupBundleListBuilder.php in Booking and Availability Management Tools for Drupal 8

Namespace

Drupal\bat

File

src/TypeGroupBundleListBuilder.php
View source
<?php

/**
 * @file
 * Contains \Drupal\bat\TypeGroupBundleListBuilder.
 */
namespace Drupal\bat;

use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Url;
use Drupal\Core\Entity\EntityInterface;

/**
 * Defines a class to build a listing of event type entities.
 *
 * @see \Drupal\bat\Entity\TypeGroupBundle
 */
class TypeGroupBundleListBuilder extends ConfigEntityListBuilder {

  /**
   * {@inheritdoc}
   */
  public function buildHeader() {
    $header['title'] = t('Name');
    return $header + parent::buildHeader();
  }

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {
    $row['title'] = [
      'data' => $entity
        ->label(),
      'class' => [
        'menu-label',
      ],
    ];
    return $row + parent::buildRow($entity);
  }

  /**
   * {@inheritdoc}
   */
  public function getDefaultOperations(EntityInterface $entity) {
    $operations = parent::getDefaultOperations($entity);

    // Place the edit operation after the operations added by field_ui.module
    // which have the weights 15, 20, 25.
    if (isset($operations['edit'])) {
      $operations['edit']['weight'] = 30;
    }
    return $operations;
  }

  /**
   * {@inheritdoc}
   */
  public function render() {
    $build = parent::render();
    $build['table']['#empty'] = $this
      ->t('No type group bundles available. <a href=":link">Add type group bundle</a>.', [
      ':link' => Url::fromRoute('entity.bat_type_group_bundle.type_add')
        ->toString(),
    ]);
    return $build;
  }

}

Classes

Namesort descending Description
TypeGroupBundleListBuilder Defines a class to build a listing of event type entities.