AssetInjectorListBuilder.php in Asset Injector 8
File
src/AssetInjectorListBuilder.php
View source
<?php
namespace Drupal\asset_injector;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
class AssetInjectorListBuilder extends ConfigEntityListBuilder {
public function buildHeader() {
$header['label'] = $this
->t('Injector');
$header['id'] = $this
->t('Machine name');
$header['themes'] = $this
->t('Themes');
return $header + parent::buildHeader();
}
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;
}
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;
}
}