3 namespace Drupal\fontyourface;
5 use Drupal\Core\Entity\EntityInterface;
6 use Drupal\Core\Entity\EntityListBuilder;
7 use Drupal\Core\Routing\LinkGeneratorTrait;
11 * Defines a class to build a listing of Font entities.
13 * @ingroup fontyourface
15 class FontListBuilder extends EntityListBuilder {
16 use LinkGeneratorTrait;
21 public function buildHeader() {
22 $header['id'] = $this->t('Font ID');
23 $header['name'] = $this->t('Name');
24 return $header + parent::buildHeader();
30 public function buildRow(EntityInterface $entity) {
31 /* @var $entity \Drupal\fontyourface\Entity\Font */
32 $row['id'] = $entity->id();
33 $row['name'] = $this->l(
37 return $row + parent::buildRow($entity);
41 * Gets this list's default operations.
43 * @param \Drupal\Core\Entity\EntityInterface $entity
44 * The entity the operations are for.
47 * The array structure is identical to the return value of
48 * self::getOperations().
50 protected function getDefaultOperations(EntityInterface $entity) {
52 if ($entity->access('update') && $entity->hasLinkTemplate('edit-form')) {
53 $operations['edit'] = [
54 'title' => $this->t('Edit'),
56 'url' => $entity->urlInfo('edit-form'),
59 if ($entity->isActivated()) {
60 $operations['disable'] = [
61 'title' => $this->t('Disable'),
63 'url' => Url::fromRoute('entity.font.deactivate', ['js' => 'nojs', 'font' => $entity->id()], ['query' => \Drupal::destination()->getAsArray()]),
66 if ($entity->isDeactivated()) {
67 $operations['enable'] = [
68 'title' => $this->t('enable'),
70 'url' => Url::fromRoute('entity.font.activate', ['js' => 'nojs', 'font' => $entity->id()], ['query' => \Drupal::destination()->getAsArray()]),