fences-8.x-2.0-rc1/modules/fences_presets/src/FencesPresetListBuilder.php
modules/fences_presets/src/FencesPresetListBuilder.php
<?php
declare(strict_types=1);
namespace Drupal\fences_presets;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
/**
* Provides a listing of fences presets.
*/
final class FencesPresetListBuilder extends ConfigEntityListBuilder {
/**
* {@inheritdoc}
*/
public function buildHeader(): array {
$header['label'] = $this->t('Label');
$header['id'] = $this->t('Machine name');
$header['status'] = $this->t('Status');
$header['description'] = $this->t('Description');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity): array {
/** @var \Drupal\fences_presets\FencesPresetInterface $entity */
$row['label'] = $entity->label();
$row['id'] = $entity->id();
$row['status'] = $entity->status() ? $this->t('Enabled') : $this->t('Disabled');
$row['description'] = $entity->get('description');
return $row + parent::buildRow($entity);
}
/**
* {@inheritdoc}
*/
public function getDefaultOperations(EntityInterface $entity) {
/** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
$operations = parent::getDefaultOperations($entity);
if (!$entity->hasLinkTemplate('duplicate-form')) {
return $operations;
}
$operations['duplicate'] = [
'title' => $this->t('Duplicate'),
'weight' => 1,
'url' => $this->ensureDestination($entity->toUrl('duplicate-form')),
];
return $operations;
}
}
