3 namespace Drupal\media\Entity;
5 use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
6 use Drupal\Core\Entity\EntityWithPluginCollectionInterface;
7 use Drupal\Core\Plugin\DefaultSingleLazyPluginCollection;
8 use Drupal\media\MediaTypeInterface;
11 * Defines the Media type configuration entity.
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"
24 * "access" = "Drupal\media\MediaTypeAccessControlHandler",
26 * "add" = "Drupal\media\MediaTypeForm",
27 * "edit" = "Drupal\media\MediaTypeForm",
28 * "delete" = "Drupal\media\Form\MediaTypeDeleteConfirmForm"
30 * "list_builder" = "Drupal\media\MediaTypeListBuilder",
31 * "route_provider" = {
32 * "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
35 * admin_permission = "administer media types",
36 * config_prefix = "type",
37 * bundle_of = "media",
41 * "status" = "status",
48 * "queue_thumbnail_downloads",
50 * "source_configuration",
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",
62 class MediaType extends ConfigEntityBundleBase implements MediaTypeInterface, EntityWithPluginCollectionInterface {
65 * The machine name of this media type.
72 * The human-readable name of the media type.
79 * A brief description of this media type.
83 protected $description;
86 * The media source ID.
93 * Whether media items should be published by default.
97 protected $status = TRUE;
100 * Whether thumbnail downloads are queued.
104 protected $queue_thumbnail_downloads = FALSE;
107 * Default value of the 'Create new revision' checkbox of this media type.
111 protected $new_revision = FALSE;
114 * The media source configuration.
118 protected $source_configuration = [];
121 * Lazy collection for the media source.
123 * @var \Drupal\Core\Plugin\DefaultSingleLazyPluginCollection
125 protected $sourcePluginCollection;
128 * Field map. Fields provided by type plugin to be stored as entity fields.
132 protected $field_map = [];
137 public function getPluginCollections() {
139 'source_configuration' => $this->sourcePluginCollection(),
146 public function getDescription() {
147 return $this->description;
153 public function setDescription($description) {
154 return $this->set('description', $description);
160 public function thumbnailDownloadsAreQueued() {
161 return $this->queue_thumbnail_downloads;
167 public function setQueueThumbnailDownloadsStatus($queue_thumbnail_downloads) {
168 return $this->set('queue_thumbnail_downloads', $queue_thumbnail_downloads);
174 public function getSource() {
175 return $this->sourcePluginCollection()->get($this->source);
179 * Returns media source lazy plugin collection.
181 * @return \Drupal\Core\Plugin\DefaultSingleLazyPluginCollection|null
182 * The tag plugin collection or NULL if the plugin ID was not set yet.
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);
188 return $this->sourcePluginCollection;
194 public function getStatus() {
195 return $this->status;
201 public function shouldCreateNewRevision() {
202 return $this->new_revision;
208 public function setNewRevision($new_revision) {
209 return $this->set('new_revision', $new_revision);
215 public function getFieldMap() {
216 return $this->field_map;
222 public function setFieldMap(array $map) {
223 return $this->set('field_map', $map);