9cde85f7f148b8018a4f297eeeaa92c66826911b
[yaffs-website] / web / modules / contrib / fontyourface / src / Entity / FontDisplay.php
1 <?php
2
3 namespace Drupal\fontyourface\Entity;
4
5 use Drupal\Core\Config\Entity\ConfigEntityBase;
6 use Drupal\fontyourface\FontDisplayInterface;
7
8 /**
9  * Defines the Font display entity.
10  *
11  * @ConfigEntityType(
12  *   id = "font_display",
13  *   label = @Translation("Font display"),
14  *   handlers = {
15  *     "list_builder" = "Drupal\fontyourface\FontDisplayListBuilder",
16  *     "form" = {
17  *       "add" = "Drupal\fontyourface\Form\FontDisplayForm",
18  *       "edit" = "Drupal\fontyourface\Form\FontDisplayForm",
19  *       "delete" = "Drupal\fontyourface\Form\FontDisplayDeleteForm"
20  *     },
21  *     "route_provider" = {
22  *       "html" = "Drupal\fontyourface\FontDisplayHtmlRouteProvider",
23  *     },
24  *   },
25  *   config_prefix = "font_display",
26  *   admin_permission = "administer font entities",
27  *   entity_keys = {
28  *     "id" = "id",
29  *     "label" = "label",
30  *     "uuid" = "uuid",
31  *     "font_url" = "font_url",
32  *     "style" = "style",
33  *     "weight" = "weight",
34  *     "fallback" = "fallback",
35  *     "selectors" = "selectors",
36  *     "theme" = "theme"
37  *   },
38  *   links = {
39  *     "canonical" = "/admin/appearance/font/font_display/{font_display}",
40  *     "add-form" = "/admin/appearance/font/font_display/add",
41  *     "edit-form" = "/admin/appearance/font/font_display/{font_display}/edit",
42  *     "delete-form" = "/admin/appearance/font/font_display/{font_display}/delete",
43  *     "collection" = "/admin/appearance/font/font_display"
44  *   }
45  * )
46  */
47 class FontDisplay extends ConfigEntityBase implements FontDisplayInterface {
48   /**
49    * The Font display ID.
50    *
51    * @var string
52    */
53   protected $id;
54
55   /**
56    * The Font display label.
57    *
58    * @var string
59    */
60   protected $label;
61
62   /**
63    * Font URL - these are unique.
64    *
65    * @var string
66    */
67   protected $font_url;
68
69   /**
70    * Font style.
71    *
72    * @var string
73    */
74   protected $style;
75
76   /**
77    * Font weight.
78    *
79    * @var string
80    */
81   protected $weight;
82
83   /**
84    * Fallback fonts when font fails to load.
85    *
86    * @var string
87    */
88   protected $fallback;
89
90   /**
91    * Selectors where font applies.
92    *
93    * @var string
94    */
95   protected $selectors;
96
97   /**
98    * Theme - where the font + selectors will be used.
99    *
100    * @var string
101    */
102   protected $theme;
103
104   /**
105    * {@inheritdoc}
106    */
107   public function getFont() {
108     return Font::loadByUrl($this->getFontUrl());
109   }
110
111   /**
112    * {@inheritdoc}
113    */
114   public function getFontUrl() {
115     return $this->get('font_url');
116   }
117
118   /**
119    * {@inheritdoc}
120    */
121   public function setFontUrl($font_url) {
122     $this->set('font_url', $font_url);
123     return $this;
124   }
125
126   /**
127    * {@inheritdoc}
128    */
129   public function getFallback() {
130     return $this->get('fallback');
131   }
132
133   /**
134    * {@inheritdoc}
135    */
136   public function setFallback($fallback) {
137     $this->set('fallback', $fallback);
138     return $this;
139   }
140
141   /**
142    * {@inheritdoc}
143    */
144   public function getSelectors() {
145     return $this->get('selectors');
146   }
147
148   /**
149    * {@inheritdoc}
150    */
151   public function setSelectors($selectors) {
152     $this->set('selectors', $selectors);
153     return $this;
154   }
155
156   /**
157    * {@inheritdoc}
158    */
159   public function getTheme() {
160     return $this->get('theme');
161   }
162
163   /**
164    * {@inheritdoc}
165    */
166   public function setTheme($theme) {
167     $this->set('theme', $theme);
168     return $this;
169   }
170
171   /**
172    * {@inheritdoc}
173    */
174   public static function loadByTheme($theme) {
175     return \Drupal::entityManager()->getStorage('font_display')->loadByProperties(['theme' => $theme]);
176   }
177
178 }