You are here

TokenCustomTypeListBuilder.php in Custom Tokens 8

File

src/TokenCustomTypeListBuilder.php
View source
<?php

namespace Drupal\token_custom;

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

/**
 * Defines a class to build a listing of custom token type entities.
 *
 * @see \Drupal\token_custom\Entity\TokenCustomType
 */
class TokenCustomTypeListBuilder extends ConfigEntityListBuilder {

  /**
   * {@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 buildHeader() {
    $header['type'] = t('Custom token type');
    $header['description'] = t('Description');
    return $header + parent::buildHeader();
  }

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {
    $row['type'] = $entity
      ->toLink()
      ->toString();
    $row['description']['data']['#markup'] = $entity
      ->getDescription();
    return $row + parent::buildRow($entity);
  }

  /**
   * {@inheritdoc}
   */
  protected function getTitle() {
    return $this
      ->t('Custom token types');
  }

}

Classes

Namesort descending Description
TokenCustomTypeListBuilder Defines a class to build a listing of custom token type entities.