0f4b1c61b4e24e6dc034bcbcadf98449aae9b7b9
[yaffs-website] / web / modules / contrib / fontyourface / modules / local_fonts / src / LocalFontConfigEntityListBuilder.php
1 <?php
2
3 namespace Drupal\local_fonts;
4
5 use Drupal\Core\Url;
6 use Drupal\Core\Link;
7 use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
8 use Drupal\Core\Entity\EntityInterface;
9 use Drupal\fontyourface\Entity\Font;
10
11 /**
12  * Provides a listing of Custom Font entities.
13  */
14 class LocalFontConfigEntityListBuilder extends ConfigEntityListBuilder {
15
16   /**
17    * {@inheritdoc}
18    */
19   public function buildHeader() {
20     $header['label'] = $this->t('Custom Font');
21     $header['id'] = $this->t('Machine name');
22     $header['font_family'] = $this->t('Font Family');
23     $header['font_view'] = $this->t('View Font');
24     $header['font_manage'] = $this->t('Enable/Disable');
25     return $header + parent::buildHeader();
26   }
27
28   /**
29    * {@inheritdoc}
30    */
31   public function buildRow(EntityInterface $entity) {
32     $row['label'] = $entity->label();
33     $row['id'] = $entity->id();
34     $row['font_family'] = $entity->font_family;
35     try {
36       $font = Font::loadByUrl('local_fonts://' . $entity->id());
37       $parameters = [
38         'js' => 'nojs',
39         'font' => $font->id(),
40       ];
41       $options = [
42         'query' => \Drupal::destination()->getAsArray(),
43       ];
44       $row['font_view'] = Link::fromTextAndUrl($this->t('View Font'), $font->toUrl('canonical'));
45       if ($font->isActivated()) {
46         $url = Url::fromRoute('entity.font.deactivate', $parameters, $options);
47         $row['font_manage'] = Link::fromTextAndUrl($this->t('Disable'), $url);
48       }
49       else {
50         $url = Url::fromRoute('entity.font.activate', $parameters, $options);
51         $row['font_manage'] = Link::fromTextAndUrl($this->t('Enable'), $url);
52       }
53     }
54     catch (Exception $e) {
55       $row['font_view'] = $this->t('Disabled');
56       $row['font_manage'] = $this->t('Disabled');
57     }
58     return $row + parent::buildRow($entity);
59   }
60
61 }