Version 1
[yaffs-website] / web / modules / contrib / fontyourface / src / FontListBuilder.php
1 <?php
2
3 namespace Drupal\fontyourface;
4
5 use Drupal\Core\Entity\EntityInterface;
6 use Drupal\Core\Entity\EntityListBuilder;
7 use Drupal\Core\Routing\LinkGeneratorTrait;
8 use Drupal\Core\Url;
9
10 /**
11  * Defines a class to build a listing of Font entities.
12  *
13  * @ingroup fontyourface
14  */
15 class FontListBuilder extends EntityListBuilder {
16   use LinkGeneratorTrait;
17
18   /**
19    * {@inheritdoc}
20    */
21   public function buildHeader() {
22     $header['id'] = $this->t('Font ID');
23     $header['name'] = $this->t('Name');
24     return $header + parent::buildHeader();
25   }
26
27   /**
28    * {@inheritdoc}
29    */
30   public function buildRow(EntityInterface $entity) {
31     /* @var $entity \Drupal\fontyourface\Entity\Font */
32     $row['id'] = $entity->id();
33     $row['name'] = $this->l(
34       $entity->label(),
35       $entity->urlInfo()
36     );
37     return $row + parent::buildRow($entity);
38   }
39
40   /**
41    * Gets this list's default operations.
42    *
43    * @param \Drupal\Core\Entity\EntityInterface $entity
44    *   The entity the operations are for.
45    *
46    * @return array
47    *   The array structure is identical to the return value of
48    *   self::getOperations().
49    */
50   protected function getDefaultOperations(EntityInterface $entity) {
51     $operations = [];
52     if ($entity->access('update') && $entity->hasLinkTemplate('edit-form')) {
53       $operations['edit'] = [
54         'title' => $this->t('Edit'),
55         'weight' => 10,
56         'url' => $entity->urlInfo('edit-form'),
57       ];
58     }
59     if ($entity->isEnabled()) {
60       $operations['disable'] = [
61         'title' => $this->t('Disable'),
62         'weight' => 100,
63         'url' => Url::fromRoute('entity.font.disable', ['js' => 'nojs', 'font' => $entity->id()], ['query' => \Drupal::destination()->getAsArray()]),
64       ];
65     }
66     if ($entity->isDisabled()) {
67       $operations['enable'] = [
68         'title' => $this->t('enable'),
69         'weight' => 100,
70         'url' => Url::fromRoute('entity.font.enable', ['js' => 'nojs', 'font' => $entity->id()], ['query' => \Drupal::destination()->getAsArray()]),
71       ];
72     }
73
74     return $operations;
75   }
76
77 }