8833f82b76af6c44607ea0308e04e1628e423183
[yaffs-website] / web / modules / contrib / media_entity / src / Entity / MediaBundle.php
1 <?php
2
3 namespace Drupal\media_entity\Entity;
4
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;
11
12 /**
13  * Defines the Media bundle configuration entity.
14  *
15  * @ConfigEntityType(
16  *   id = "media_bundle",
17  *   label = @Translation("Media bundle"),
18  *   handlers = {
19  *     "form" = {
20  *       "add" = "Drupal\media_entity\MediaBundleForm",
21  *       "edit" = "Drupal\media_entity\MediaBundleForm",
22  *       "delete" = "Drupal\media_entity\Form\MediaBundleDeleteConfirm"
23  *     },
24  *     "list_builder" = "Drupal\media_entity\MediaBundleListBuilder",
25  *     "route_provider" = {
26  *       "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
27  *     }
28  *   },
29  *   admin_permission = "administer media bundles",
30  *   config_prefix = "bundle",
31  *   bundle_of = "media",
32  *   entity_keys = {
33  *     "id" = "id",
34  *     "label" = "label"
35  *   },
36  *   config_export = {
37  *     "id",
38  *     "label",
39  *     "description",
40  *     "type",
41  *     "queue_thumbnail_downloads",
42  *     "new_revision",
43  *     "third_party_settings",
44  *     "type_configuration",
45  *     "field_map",
46  *     "status",
47  *   },
48  *   links = {
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",
53  *   }
54  * )
55  */
56 class MediaBundle extends ConfigEntityBundleBase implements MediaBundleInterface, EntityWithPluginCollectionInterface, EntityDescriptionInterface {
57
58   /**
59    * The machine name of this media bundle.
60    *
61    * @var string
62    */
63   public $id;
64
65   /**
66    * The human-readable name of the media bundle.
67    *
68    * @var string
69    */
70   public $label;
71
72   /**
73    * A brief description of this media bundle.
74    *
75    * @var string
76    */
77   public $description;
78
79   /**
80    * The type plugin id.
81    *
82    * @var string
83    */
84   public $type = 'generic';
85
86   /**
87    * Are thumbnail downloads queued.
88    *
89    * @var bool
90    */
91   public $queue_thumbnail_downloads = FALSE;
92
93   /**
94    * Default value of the 'Create new revision' checkbox of this media bundle.
95    *
96    * @var bool
97    */
98   protected $new_revision = FALSE;
99
100   /**
101    * The type plugin configuration.
102    *
103    * @var array
104    */
105   public $type_configuration = [];
106
107   /**
108    * Type lazy plugin collection.
109    *
110    * @var \Drupal\Core\Plugin\DefaultSingleLazyPluginCollection
111    */
112   protected $typePluginCollection;
113
114   /**
115    * Field map. Fields provided by type plugin to be stored as entity fields.
116    *
117    * @var array
118    */
119   public $field_map = [];
120
121   /**
122    * Default status of this media bundle.
123    *
124    * @var array
125    */
126   public $status = TRUE;
127
128   /**
129    * {@inheritdoc}
130    */
131   public function id() {
132     return $this->id;
133   }
134
135   /**
136    * {@inheritdoc}
137    */
138   public function getPluginCollections() {
139     return [
140       'type_configuration' => $this->typePluginCollection(),
141     ];
142   }
143
144   /**
145    * {@inheritdoc}
146    */
147   public static function getLabel(MediaInterface $media) {
148     $bundle = static::load($media->bundle());
149     return $bundle ? $bundle->label() : FALSE;
150   }
151
152   /**
153    * {@inheritdoc}
154    */
155   public static function exists($id) {
156     return (bool) static::load($id);
157   }
158
159   /**
160    * {@inheritdoc}
161    */
162   public function getDescription() {
163     return $this->description;
164   }
165
166   /**
167    * {@inheritdoc}
168    */
169   public function setDescription($description) {
170     $this->description = $description;
171     return $this;
172   }
173
174   /**
175    * {@inheritdoc}
176    */
177   public function getTypeConfiguration() {
178     return $this->type_configuration;
179   }
180
181   /**
182    * {@inheritdoc}
183    */
184   public function setTypeConfiguration($configuration) {
185     $this->type_configuration = $configuration;
186     $this->typePluginCollection = NULL;
187   }
188
189   /**
190    * {@inheritdoc}
191    */
192   public function getQueueThumbnailDownloads() {
193     return $this->queue_thumbnail_downloads;
194   }
195
196   /**
197    * {@inheritdoc}
198    */
199   public function setQueueThumbnailDownloads($queue_thumbnail_downloads) {
200     $this->queue_thumbnail_downloads = $queue_thumbnail_downloads;
201   }
202
203   /**
204    * {@inheritdoc}
205    */
206   public function getType() {
207     return $this->typePluginCollection()->get($this->type);
208   }
209
210   /**
211    * Returns type lazy plugin collection.
212    *
213    * @return \Drupal\Core\Plugin\DefaultSingleLazyPluginCollection
214    *   The tag plugin collection.
215    */
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);
219     }
220     return $this->typePluginCollection;
221   }
222
223   /**
224    * {@inheritdoc}
225    */
226   public function getStatus() {
227     return $this->status;
228   }
229
230   /**
231    * {@inheritdoc}
232    */
233   public function shouldCreateNewRevision() {
234     return $this->new_revision;
235   }
236
237   /**
238    * {@inheritdoc}
239    */
240   public function setNewRevision($new_revision) {
241     $this->new_revision = $new_revision;
242   }
243
244 }