Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / fontyourface / modules / local_fonts / src / LocalFontConfigEntityListBuilder.php
index 6b42c8226df574456e05da120b5f93cd17726d63..0f4b1c61b4e24e6dc034bcbcadf98449aae9b7b9 100644 (file)
@@ -2,8 +2,11 @@
 
 namespace Drupal\local_fonts;
 
+use Drupal\Core\Url;
+use Drupal\Core\Link;
 use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
 use Drupal\Core\Entity\EntityInterface;
+use Drupal\fontyourface\Entity\Font;
 
 /**
  * Provides a listing of Custom Font entities.
@@ -17,6 +20,8 @@ class LocalFontConfigEntityListBuilder extends ConfigEntityListBuilder {
     $header['label'] = $this->t('Custom Font');
     $header['id'] = $this->t('Machine name');
     $header['font_family'] = $this->t('Font Family');
+    $header['font_view'] = $this->t('View Font');
+    $header['font_manage'] = $this->t('Enable/Disable');
     return $header + parent::buildHeader();
   }
 
@@ -27,6 +32,29 @@ class LocalFontConfigEntityListBuilder extends ConfigEntityListBuilder {
     $row['label'] = $entity->label();
     $row['id'] = $entity->id();
     $row['font_family'] = $entity->font_family;
+    try {
+      $font = Font::loadByUrl('local_fonts://' . $entity->id());
+      $parameters = [
+        'js' => 'nojs',
+        'font' => $font->id(),
+      ];
+      $options = [
+        'query' => \Drupal::destination()->getAsArray(),
+      ];
+      $row['font_view'] = Link::fromTextAndUrl($this->t('View Font'), $font->toUrl('canonical'));
+      if ($font->isActivated()) {
+        $url = Url::fromRoute('entity.font.deactivate', $parameters, $options);
+        $row['font_manage'] = Link::fromTextAndUrl($this->t('Disable'), $url);
+      }
+      else {
+        $url = Url::fromRoute('entity.font.activate', $parameters, $options);
+        $row['font_manage'] = Link::fromTextAndUrl($this->t('Enable'), $url);
+      }
+    }
+    catch (Exception $e) {
+      $row['font_view'] = $this->t('Disabled');
+      $row['font_manage'] = $this->t('Disabled');
+    }
     return $row + parent::buildRow($entity);
   }