FontListBuilder.php in @font-your-face 8.3
File
src/FontListBuilder.php
View source
<?php
namespace Drupal\fontyourface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Link;
use Drupal\Core\Url;
class FontListBuilder extends EntityListBuilder {
public function buildHeader() {
$header['id'] = $this
->t('Font ID');
$header['name'] = $this
->t('Name');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row['id'] = $entity
->id();
$row['name'] = Link::fromTextAndUrl($entity
->label(), $entity
->toUrl())
->toString();
return $row + parent::buildRow($entity);
}
protected function getDefaultOperations(EntityInterface $entity) {
$operations = [];
if ($entity
->access('update') && $entity
->hasLinkTemplate('edit-form')) {
$operations['edit'] = [
'title' => $this
->t('Edit'),
'weight' => 10,
'url' => $entity
->toUrl('edit-form'),
];
}
if ($entity
->isActivated()) {
$operations['disable'] = [
'title' => $this
->t('Disable'),
'weight' => 100,
'url' => Url::fromRoute('entity.font.deactivate', [
'js' => 'nojs',
'font' => $entity
->id(),
], [
'query' => \Drupal::destination()
->getAsArray(),
]),
];
}
if ($entity
->isDeactivated()) {
$operations['enable'] = [
'title' => $this
->t('enable'),
'weight' => 100,
'url' => Url::fromRoute('entity.font.activate', [
'js' => 'nojs',
'font' => $entity
->id(),
], [
'query' => \Drupal::destination()
->getAsArray(),
]),
];
}
return $operations;
}
}