You are here

AssetInjectorListBuilder.php in Asset Injector 8

Same filename and directory in other branches
  1. 8.2 src/AssetInjectorListBuilder.php

File

src/AssetInjectorListBuilder.php
View source
<?php

namespace Drupal\asset_injector;

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

/**
 * Provides a listing of Asset Injector entities.
 */
class AssetInjectorListBuilder extends ConfigEntityListBuilder {

  /**
   * {@inheritdoc}
   */
  public function buildHeader() {
    $header['label'] = $this
      ->t('Injector');
    $header['id'] = $this
      ->t('Machine name');
    $header['themes'] = $this
      ->t('Themes');
    return $header + parent::buildHeader();
  }

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {
    $data['label'] = $entity
      ->label();
    $data['id'] = $entity
      ->id();
    $themes = $entity->themes;
    if (empty($themes)) {
      $data['themes'] = $this
        ->t('All');
    }
    else {
      $data['themes'] = implode(', ', $themes);
    }
    $row = [
      'class' => $entity
        ->status() ? 'enabled' : 'disabled',
      'data' => $data + parent::buildRow($entity),
    ];
    return $row;
  }

  /**
   * {@inheritdoc}
   */
  public function getDefaultOperations(EntityInterface $entity) {
    $operations = parent::getDefaultOperations($entity);
    if ($entity
      ->hasLinkTemplate('duplicate-form')) {
      $operations['duplicate'] = [
        'title' => $this
          ->t('Duplicate'),
        'weight' => 15,
        'url' => $entity
          ->toUrl('duplicate-form'),
      ];
    }
    return $operations;
  }

}

Classes

Namesort descending Description
AssetInjectorListBuilder Provides a listing of Asset Injector entities.