TagListBuilder.php in Extensible BBCode 4.0.x
File
src/TagListBuilder.php
View source
<?php
namespace Drupal\xbbcode;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
class TagListBuilder extends EntityListBuilder {
public function buildHeader() : array {
$header['tag'] = $this
->t('Name');
$header['description'] = $this
->t('Description');
$header['sample'] = $this
->t('Sample');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) : array {
$row['tag'] = $entity
->label();
$row['description'] = $entity
->getDescription();
$row['sample'] = [
'data' => str_replace('{{ name }}', $entity
->getName(), $entity
->getSample()),
'style' => 'font-family:monospace',
];
return $row + parent::buildRow($entity);
}
protected function getDefaultOperations(EntityInterface $entity) : array {
$operations = parent::getDefaultOperations($entity);
if (!$entity
->access('update')) {
$operations['view'] = [
'title' => $this
->t('View'),
'url' => $entity
->toUrl('view-form'),
];
}
$operations['copy'] = [
'title' => $this
->t('Copy'),
'url' => $entity
->toUrl('copy-form'),
'weight' => 20,
];
return $operations;
}
}