You are here

CalendarEventTypeListBuilder.php in Opigno calendar event 3.x

Same filename and directory in other branches
  1. 8 src/CalendarEventTypeListBuilder.php

File

src/CalendarEventTypeListBuilder.php
View source
<?php

namespace Drupal\opigno_calendar_event;

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

/**
 * Defines a class to build a listing of calendar event type entities.
 *
 * @see \Drupal\opigno_calendar_event\Entity\CalendarEventType
 */
class CalendarEventTypeListBuilder extends ConfigEntityListBuilder {

  /**
   * {@inheritdoc}
   */
  public function buildHeader() {
    $header['title'] = t('Label');
    $header['description'] = [
      'data' => t('Description'),
      'class' => [
        RESPONSIVE_PRIORITY_MEDIUM,
      ],
    ];
    return $header + parent::buildHeader();
  }

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

    /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
    $row['title'] = [
      'data' => $entity
        ->label(),
      'class' => [
        'menu-label',
      ],
    ];
    $row['description']['data'] = [
      '#markup' => $entity
        ->get('description'),
    ];
    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 calendar event types available. <a href=":link">Add event type</a>.', [
      ':link' => Url::fromRoute('entity.opigno_calendar_event_type.add_form')
        ->toString(),
    ]);
    return $build;
  }

}

Classes

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