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