You are here

MediaBundleListBuilder.php in Media entity 8

File

src/MediaBundleListBuilder.php
View source
<?php

namespace Drupal\media_entity;

use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityHandlerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Url;

/**
 * Provides a listing of media bundles.
 */
class MediaBundleListBuilder extends ConfigEntityListBuilder implements EntityHandlerInterface {

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

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

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

}

Classes

Namesort descending Description
MediaBundleListBuilder Provides a listing of media bundles.