VoteTypeListBuilder.php in Voting API 8.3
File
src/VoteTypeListBuilder.php
View source
<?php
namespace Drupal\votingapi;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Url;
use Drupal\Core\Entity\EntityInterface;
class VoteTypeListBuilder extends ConfigEntityListBuilder {
public function buildHeader() {
$header['id'] = $this
->t('Id');
$header['label'] = $this
->t('Label');
$header['value_type'] = $this
->t('Value type');
$header['description'] = [
'data' => $this
->t('Description'),
'class' => [
RESPONSIVE_PRIORITY_MEDIUM,
],
];
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row['id']['data'] = [
'#markup' => $entity
->id(),
];
$row['label'] = [
'data' => $entity
->label(),
'class' => [
'menu-label',
],
];
$row['value_type']['data'] = [
'#markup' => $entity
->getValueType(),
];
$row['description']['data'] = [
'#markup' => $entity
->getDescription(),
];
return $row + parent::buildRow($entity);
}
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
if (isset($operations['edit'])) {
$operations['edit']['weight'] = 30;
}
return $operations;
}
public function render() {
$build = parent::render();
$build['table']['#empty'] = $this
->t('No vote types available. <a href="@link">Add vote type</a>.', [
'@link' => Url::fromRoute('votingapi.type_add')
->toString(),
]);
return $build;
}
}