You are here

VoteTypeListBuilder.php in Voting API 8.3

Namespace

Drupal\votingapi

File

src/VoteTypeListBuilder.php
View source
<?php

namespace Drupal\votingapi;

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

/**
 * Defines a class to build a listing of vote type entities.
 *
 * @see \Drupal\votingapi\Entity\VoteType
 */
class VoteTypeListBuilder extends ConfigEntityListBuilder {

  /**
   * {@inheritdoc}
   */
  public function buildHeader() {
    $header['id'] = $this
      ->t('Id');
    $header['label'] = $this
      ->t('Label');
    $header['value_type'] = $this
      ->t('Value type');
    $header['description'] = [
      'data' => $this
        ->t('Description'),
      'class' => [
        RESPONSIVE_PRIORITY_MEDIUM,
      ],
    ];
    return $header + parent::buildHeader();
  }

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {
    $row['id']['data'] = [
      '#markup' => $entity
        ->id(),
    ];
    $row['label'] = [
      'data' => $entity
        ->label(),
      'class' => [
        'menu-label',
      ],
    ];
    $row['value_type']['data'] = [
      '#markup' => $entity
        ->getValueType(),
    ];
    $row['description']['data'] = [
      '#markup' => $entity
        ->getDescription(),
    ];
    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 vote types available. <a href="@link">Add vote type</a>.', [
      '@link' => Url::fromRoute('votingapi.type_add')
        ->toString(),
    ]);
    return $build;
  }

}

Classes

Namesort descending Description
VoteTypeListBuilder Defines a class to build a listing of vote type entities.