3 namespace Drupal\local_fonts;
7 use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
8 use Drupal\Core\Entity\EntityInterface;
9 use Drupal\fontyourface\Entity\Font;
12 * Provides a listing of Custom Font entities.
14 class LocalFontConfigEntityListBuilder extends ConfigEntityListBuilder {
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();
31 public function buildRow(EntityInterface $entity) {
32 $row['label'] = $entity->label();
33 $row['id'] = $entity->id();
34 $row['font_family'] = $entity->font_family;
36 $font = Font::loadByUrl('local_fonts://' . $entity->id());
39 'font' => $font->id(),
42 'query' => \Drupal::destination()->getAsArray(),
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);
50 $url = Url::fromRoute('entity.font.activate', $parameters, $options);
51 $row['font_manage'] = Link::fromTextAndUrl($this->t('Enable'), $url);
54 catch (Exception $e) {
55 $row['font_view'] = $this->t('Disabled');
56 $row['font_manage'] = $this->t('Disabled');
58 return $row + parent::buildRow($entity);