Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / media / src / Entity / MediaType.php
1 <?php
2
3 namespace Drupal\media\Entity;
4
5 use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
6 use Drupal\Core\Entity\EntityWithPluginCollectionInterface;
7 use Drupal\Core\Plugin\DefaultSingleLazyPluginCollection;
8 use Drupal\media\MediaTypeInterface;
9
10 /**
11  * Defines the Media type configuration entity.
12  *
13  * @ConfigEntityType(
14  *   id = "media_type",
15  *   label = @Translation("Media type"),
16  *   label_collection = @Translation("Media types"),
17  *   label_singular = @Translation("media type"),
18  *   label_plural = @Translation("media types"),
19  *   label_count = @PluralTranslation(
20  *     singular = "@count media type",
21  *     plural = "@count media types"
22  *   ),
23  *   handlers = {
24  *     "form" = {
25  *       "add" = "Drupal\media\MediaTypeForm",
26  *       "edit" = "Drupal\media\MediaTypeForm",
27  *       "delete" = "Drupal\media\Form\MediaTypeDeleteConfirmForm"
28  *     },
29  *     "list_builder" = "Drupal\media\MediaTypeListBuilder",
30  *     "route_provider" = {
31  *       "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
32  *     }
33  *   },
34  *   admin_permission = "administer media types",
35  *   config_prefix = "type",
36  *   bundle_of = "media",
37  *   entity_keys = {
38  *     "id" = "id",
39  *     "label" = "label",
40  *     "status" = "status",
41  *   },
42  *   config_export = {
43  *     "id",
44  *     "label",
45  *     "description",
46  *     "source",
47  *     "queue_thumbnail_downloads",
48  *     "new_revision",
49  *     "source_configuration",
50  *     "field_map",
51  *     "status",
52  *   },
53  *   links = {
54  *     "add-form" = "/admin/structure/media/add",
55  *     "edit-form" = "/admin/structure/media/manage/{media_type}",
56  *     "delete-form" = "/admin/structure/media/manage/{media_type}/delete",
57  *     "collection" = "/admin/structure/media",
58  *   },
59  * )
60  */
61 class MediaType extends ConfigEntityBundleBase implements MediaTypeInterface, EntityWithPluginCollectionInterface {
62
63   /**
64    * The machine name of this media type.
65    *
66    * @var string
67    */
68   protected $id;
69
70   /**
71    * The human-readable name of the media type.
72    *
73    * @var string
74    */
75   protected $label;
76
77   /**
78    * A brief description of this media type.
79    *
80    * @var string
81    */
82   protected $description;
83
84   /**
85    * The media source ID.
86    *
87    * @var string
88    */
89   protected $source;
90
91   /**
92    * Whether media items should be published by default.
93    *
94    * @var bool
95    */
96   protected $status = TRUE;
97
98   /**
99    * Whether thumbnail downloads are queued.
100    *
101    * @var bool
102    */
103   protected $queue_thumbnail_downloads = FALSE;
104
105   /**
106    * Default value of the 'Create new revision' checkbox of this media type.
107    *
108    * @var bool
109    */
110   protected $new_revision = FALSE;
111
112   /**
113    * The media source configuration.
114    *
115    * @var array
116    */
117   protected $source_configuration = [];
118
119   /**
120    * Lazy collection for the media source.
121    *
122    * @var \Drupal\Core\Plugin\DefaultSingleLazyPluginCollection
123    */
124   protected $sourcePluginCollection;
125
126   /**
127    * Field map. Fields provided by type plugin to be stored as entity fields.
128    *
129    * @var array
130    */
131   protected $field_map = [];
132
133   /**
134    * {@inheritdoc}
135    */
136   public function getPluginCollections() {
137     return [
138       'source_configuration' => $this->sourcePluginCollection(),
139     ];
140   }
141
142   /**
143    * {@inheritdoc}
144    */
145   public function getDescription() {
146     return $this->description;
147   }
148
149   /**
150    * {@inheritdoc}
151    */
152   public function setDescription($description) {
153     return $this->set('description', $description);
154   }
155
156   /**
157    * {@inheritdoc}
158    */
159   public function thumbnailDownloadsAreQueued() {
160     return $this->queue_thumbnail_downloads;
161   }
162
163   /**
164    * {@inheritdoc}
165    */
166   public function setQueueThumbnailDownloadsStatus($queue_thumbnail_downloads) {
167     return $this->set('queue_thumbnail_downloads', $queue_thumbnail_downloads);
168   }
169
170   /**
171    * {@inheritdoc}
172    */
173   public function getSource() {
174     return $this->sourcePluginCollection()->get($this->source);
175   }
176
177   /**
178    * Returns media source lazy plugin collection.
179    *
180    * @return \Drupal\Core\Plugin\DefaultSingleLazyPluginCollection|null
181    *   The tag plugin collection or NULL if the plugin ID was not set yet.
182    */
183   protected function sourcePluginCollection() {
184     if (!$this->sourcePluginCollection && $this->source) {
185       $this->sourcePluginCollection = new DefaultSingleLazyPluginCollection(\Drupal::service('plugin.manager.media.source'), $this->source, $this->source_configuration);
186     }
187     return $this->sourcePluginCollection;
188   }
189
190   /**
191    * {@inheritdoc}
192    */
193   public function getStatus() {
194     return $this->status;
195   }
196
197   /**
198    * {@inheritdoc}
199    */
200   public function shouldCreateNewRevision() {
201     return $this->new_revision;
202   }
203
204   /**
205    * {@inheritdoc}
206    */
207   public function setNewRevision($new_revision) {
208     return $this->set('new_revision', $new_revision);
209   }
210
211   /**
212    * {@inheritdoc}
213    */
214   public function getFieldMap() {
215     return $this->field_map;
216   }
217
218   /**
219    * {@inheritdoc}
220    */
221   public function setFieldMap(array $map) {
222     return $this->set('field_map', $map);
223   }
224
225 }