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"
25 * "add" = "Drupal\media\MediaTypeForm",
26 * "edit" = "Drupal\media\MediaTypeForm",
27 * "delete" = "Drupal\media\Form\MediaTypeDeleteConfirmForm"
29 * "list_builder" = "Drupal\media\MediaTypeListBuilder",
30 * "route_provider" = {
31 * "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
34 * admin_permission = "administer media types",
35 * config_prefix = "type",
36 * bundle_of = "media",
40 * "status" = "status",
47 * "queue_thumbnail_downloads",
49 * "source_configuration",
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",
61 class MediaType extends ConfigEntityBundleBase implements MediaTypeInterface, EntityWithPluginCollectionInterface {
64 * The machine name of this media type.
71 * The human-readable name of the media type.
78 * A brief description of this media type.
82 protected $description;
85 * The media source ID.
92 * Whether media items should be published by default.
96 protected $status = TRUE;
99 * Whether thumbnail downloads are queued.
103 protected $queue_thumbnail_downloads = FALSE;
106 * Default value of the 'Create new revision' checkbox of this media type.
110 protected $new_revision = FALSE;
113 * The media source configuration.
117 protected $source_configuration = [];
120 * Lazy collection for the media source.
122 * @var \Drupal\Core\Plugin\DefaultSingleLazyPluginCollection
124 protected $sourcePluginCollection;
127 * Field map. Fields provided by type plugin to be stored as entity fields.
131 protected $field_map = [];
136 public function getPluginCollections() {
138 'source_configuration' => $this->sourcePluginCollection(),
145 public function getDescription() {
146 return $this->description;
152 public function setDescription($description) {
153 return $this->set('description', $description);
159 public function thumbnailDownloadsAreQueued() {
160 return $this->queue_thumbnail_downloads;
166 public function setQueueThumbnailDownloadsStatus($queue_thumbnail_downloads) {
167 return $this->set('queue_thumbnail_downloads', $queue_thumbnail_downloads);
173 public function getSource() {
174 return $this->sourcePluginCollection()->get($this->source);
178 * Returns media source lazy plugin collection.
180 * @return \Drupal\Core\Plugin\DefaultSingleLazyPluginCollection|null
181 * The tag plugin collection or NULL if the plugin ID was not set yet.
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);
187 return $this->sourcePluginCollection;
193 public function getStatus() {
194 return $this->status;
200 public function shouldCreateNewRevision() {
201 return $this->new_revision;
207 public function setNewRevision($new_revision) {
208 return $this->set('new_revision', $new_revision);
214 public function getFieldMap() {
215 return $this->field_map;
221 public function setFieldMap(array $map) {
222 return $this->set('field_map', $map);