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 * @see \Drupal\media\MediaTypeInterface::thumbnailDownloadsAreQueued()
106 protected $queue_thumbnail_downloads = FALSE;
109 * Default value of the 'Create new revision' checkbox of this media type.
113 protected $new_revision = FALSE;
116 * The media source configuration.
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.
126 * @see \Drupal\media\MediaTypeInterface::getSource()
128 protected $source_configuration = [];
131 * Lazy collection for the media source.
133 * @var \Drupal\Core\Plugin\DefaultSingleLazyPluginCollection
135 protected $sourcePluginCollection;
138 * The metadata field map.
142 * @see \Drupal\media\MediaTypeInterface::getFieldMap()
144 protected $field_map = [];
149 public function getPluginCollections() {
151 'source_configuration' => $this->sourcePluginCollection(),
158 public function getDescription() {
159 return $this->description;
165 public function setDescription($description) {
166 return $this->set('description', $description);
172 public function thumbnailDownloadsAreQueued() {
173 return $this->queue_thumbnail_downloads;
179 public function setQueueThumbnailDownloadsStatus($queue_thumbnail_downloads) {
180 return $this->set('queue_thumbnail_downloads', $queue_thumbnail_downloads);
186 public function getSource() {
187 return $this->sourcePluginCollection()->get($this->source);
191 * Returns media source lazy plugin collection.
193 * @return \Drupal\Core\Plugin\DefaultSingleLazyPluginCollection|null
194 * The tag plugin collection or NULL if the plugin ID was not set yet.
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);
200 return $this->sourcePluginCollection;
206 public function getStatus() {
207 return $this->status;
213 public function shouldCreateNewRevision() {
214 return $this->new_revision;
220 public function setNewRevision($new_revision) {
221 return $this->set('new_revision', $new_revision);
227 public function getFieldMap() {
228 return $this->field_map;
234 public function setFieldMap(array $map) {
235 return $this->set('field_map', $map);