Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[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    * @see \Drupal\media\MediaTypeInterface::thumbnailDownloadsAreQueued()
105    */
106   protected $queue_thumbnail_downloads = FALSE;
107
108   /**
109    * Default value of the 'Create new revision' checkbox of this media type.
110    *
111    * @var bool
112    */
113   protected $new_revision = FALSE;
114
115   /**
116    * The media source configuration.
117    *
118    * A media source can provide a configuration form with source plugin-specific
119    * configuration settings, which must at least include a source_field element
120    * containing a the name of the source field for the media type. The source
121    * configuration is defined by, and used to load, the source plugin. See
122    * \Drupal\media\MediaTypeInterface for an explanation of media sources.
123    *
124    * @var array
125    *
126    * @see \Drupal\media\MediaTypeInterface::getSource()
127    */
128   protected $source_configuration = [];
129
130   /**
131    * Lazy collection for the media source.
132    *
133    * @var \Drupal\Core\Plugin\DefaultSingleLazyPluginCollection
134    */
135   protected $sourcePluginCollection;
136
137   /**
138    * The metadata field map.
139    *
140    * @var array
141    *
142    * @see \Drupal\media\MediaTypeInterface::getFieldMap()
143    */
144   protected $field_map = [];
145
146   /**
147    * {@inheritdoc}
148    */
149   public function getPluginCollections() {
150     return [
151       'source_configuration' => $this->sourcePluginCollection(),
152     ];
153   }
154
155   /**
156    * {@inheritdoc}
157    */
158   public function getDescription() {
159     return $this->description;
160   }
161
162   /**
163    * {@inheritdoc}
164    */
165   public function setDescription($description) {
166     return $this->set('description', $description);
167   }
168
169   /**
170    * {@inheritdoc}
171    */
172   public function thumbnailDownloadsAreQueued() {
173     return $this->queue_thumbnail_downloads;
174   }
175
176   /**
177    * {@inheritdoc}
178    */
179   public function setQueueThumbnailDownloadsStatus($queue_thumbnail_downloads) {
180     return $this->set('queue_thumbnail_downloads', $queue_thumbnail_downloads);
181   }
182
183   /**
184    * {@inheritdoc}
185    */
186   public function getSource() {
187     return $this->sourcePluginCollection()->get($this->source);
188   }
189
190   /**
191    * Returns media source lazy plugin collection.
192    *
193    * @return \Drupal\Core\Plugin\DefaultSingleLazyPluginCollection|null
194    *   The tag plugin collection or NULL if the plugin ID was not set yet.
195    */
196   protected function sourcePluginCollection() {
197     if (!$this->sourcePluginCollection && $this->source) {
198       $this->sourcePluginCollection = new DefaultSingleLazyPluginCollection(\Drupal::service('plugin.manager.media.source'), $this->source, $this->source_configuration);
199     }
200     return $this->sourcePluginCollection;
201   }
202
203   /**
204    * {@inheritdoc}
205    */
206   public function getStatus() {
207     return $this->status;
208   }
209
210   /**
211    * {@inheritdoc}
212    */
213   public function shouldCreateNewRevision() {
214     return $this->new_revision;
215   }
216
217   /**
218    * {@inheritdoc}
219    */
220   public function setNewRevision($new_revision) {
221     return $this->set('new_revision', $new_revision);
222   }
223
224   /**
225    * {@inheritdoc}
226    */
227   public function getFieldMap() {
228     return $this->field_map;
229   }
230
231   /**
232    * {@inheritdoc}
233    */
234   public function setFieldMap(array $map) {
235     return $this->set('field_map', $map);
236   }
237
238 }