3 namespace Drupal\media_entity\Entity;
5 use Drupal\Core\Entity\EntityDescriptionInterface;
6 use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
7 use Drupal\Core\Entity\EntityWithPluginCollectionInterface;
8 use Drupal\Core\Plugin\DefaultSingleLazyPluginCollection;
9 use Drupal\media_entity\MediaBundleInterface;
10 use Drupal\media_entity\MediaInterface;
13 * Defines the Media bundle configuration entity.
16 * id = "media_bundle",
17 * label = @Translation("Media bundle"),
20 * "add" = "Drupal\media_entity\MediaBundleForm",
21 * "edit" = "Drupal\media_entity\MediaBundleForm",
22 * "delete" = "Drupal\media_entity\Form\MediaBundleDeleteConfirm"
24 * "list_builder" = "Drupal\media_entity\MediaBundleListBuilder",
25 * "route_provider" = {
26 * "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
29 * admin_permission = "administer media bundles",
30 * config_prefix = "bundle",
31 * bundle_of = "media",
41 * "queue_thumbnail_downloads",
43 * "third_party_settings",
44 * "type_configuration",
49 * "add-form" = "/admin/structure/media/add",
50 * "edit-form" = "/admin/structure/media/manage/{media_bundle}",
51 * "delete-form" = "/admin/structure/media/manage/{media_bundle}/delete",
52 * "collection" = "/admin/structure/media",
56 class MediaBundle extends ConfigEntityBundleBase implements MediaBundleInterface, EntityWithPluginCollectionInterface, EntityDescriptionInterface {
59 * The machine name of this media bundle.
66 * The human-readable name of the media bundle.
73 * A brief description of this media bundle.
84 public $type = 'generic';
87 * Are thumbnail downloads queued.
91 public $queue_thumbnail_downloads = FALSE;
94 * Default value of the 'Create new revision' checkbox of this media bundle.
98 protected $new_revision = FALSE;
101 * The type plugin configuration.
105 public $type_configuration = [];
108 * Type lazy plugin collection.
110 * @var \Drupal\Core\Plugin\DefaultSingleLazyPluginCollection
112 protected $typePluginCollection;
115 * Field map. Fields provided by type plugin to be stored as entity fields.
119 public $field_map = [];
122 * Default status of this media bundle.
126 public $status = TRUE;
131 public function id() {
138 public function getPluginCollections() {
140 'type_configuration' => $this->typePluginCollection(),
147 public static function getLabel(MediaInterface $media) {
148 $bundle = static::load($media->bundle());
149 return $bundle ? $bundle->label() : FALSE;
155 public static function exists($id) {
156 return (bool) static::load($id);
162 public function getDescription() {
163 return $this->description;
169 public function setDescription($description) {
170 $this->description = $description;
177 public function getTypeConfiguration() {
178 return $this->type_configuration;
184 public function setTypeConfiguration($configuration) {
185 $this->type_configuration = $configuration;
186 $this->typePluginCollection = NULL;
192 public function getQueueThumbnailDownloads() {
193 return $this->queue_thumbnail_downloads;
199 public function setQueueThumbnailDownloads($queue_thumbnail_downloads) {
200 $this->queue_thumbnail_downloads = $queue_thumbnail_downloads;
206 public function getType() {
207 return $this->typePluginCollection()->get($this->type);
211 * Returns type lazy plugin collection.
213 * @return \Drupal\Core\Plugin\DefaultSingleLazyPluginCollection
214 * The tag plugin collection.
216 protected function typePluginCollection() {
217 if (!$this->typePluginCollection) {
218 $this->typePluginCollection = new DefaultSingleLazyPluginCollection(\Drupal::service('plugin.manager.media_entity.type'), $this->type, $this->type_configuration);
220 return $this->typePluginCollection;
226 public function getStatus() {
227 return $this->status;
233 public function shouldCreateNewRevision() {
234 return $this->new_revision;
240 public function setNewRevision($new_revision) {
241 $this->new_revision = $new_revision;