You are here

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

Namespace

Drupal\bat_unit

File

modules/bat_unit/src/UnitTypeListBuilder.php
View source
<?php

/**
 * @file
 * Contains \Drupal\bat_unit\UnitTypeListBuilder.
 */
namespace Drupal\bat_unit;

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Defines a class to build a listing of Unit type entities.
 *
 * @ingroup bat
 */
class UnitTypeListBuilder extends EntityListBuilder {

  /**
   * Constructs a new UnitTypeListBuilder object.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
   *   The entity type definition.
   * @param \Drupal\Core\Entity\EntityStorageInterface $storage
   *   The entity storage class.
   */
  public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage) {
    parent::__construct($entity_type, $storage);
  }

  /**
   * {@inheritdoc}
   */
  public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
    return new static($entity_type, $container
      ->get('entity_type.manager')
      ->getStorage($entity_type
      ->id()));
  }

  /**
   * {@inheritdoc}
   */
  public function buildHeader() {
    $header = [
      'id' => [
        'data' => $this
          ->t('Unit type ID'),
        'field' => 'id',
        'specifier' => 'id',
        'class' => [
          RESPONSIVE_PRIORITY_LOW,
        ],
      ],
      'name' => [
        'data' => $this
          ->t('Name'),
        'field' => 'name',
        'specifier' => 'name',
        'class' => [
          RESPONSIVE_PRIORITY_LOW,
        ],
      ],
      'type' => [
        'data' => $this
          ->t('Type'),
        'field' => 'type',
        'specifier' => 'type',
        'class' => [
          RESPONSIVE_PRIORITY_LOW,
        ],
      ],
      'status' => [
        'data' => $this
          ->t('Status'),
        'field' => 'status',
        'specifier' => 'status',
        'class' => [
          RESPONSIVE_PRIORITY_LOW,
        ],
      ],
    ];
    return $header + parent::buildHeader();
  }

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {

    /* @var $entity \Drupal\bat_unit\Entity\UnitType */
    $row['id'] = $entity
      ->id();
    $row['name'] = Link::fromTextAndUrl($entity
      ->label(), new Url('entity.bat_unit_type.edit_form', [
      'bat_unit_type' => $entity
        ->id(),
    ]));
    $row['bundle'] = bat_type_bundle_load($entity
      ->bundle())
      ->label();
    $row['status'] = $entity
      ->getStatus() ? t('Published') : t('Unpublished');
    return $row + parent::buildRow($entity);
  }

}

Classes

Namesort descending Description
UnitTypeListBuilder Defines a class to build a listing of Unit type entities.