3 namespace Drupal\Core\Entity;
5 use Drupal\Core\Field\FieldDefinitionInterface;
6 use Drupal\Core\Field\FieldStorageDefinitionInterface;
7 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
8 use Symfony\Component\DependencyInjection\ContainerAwareTrait;
11 * Provides a wrapper around many other services relating to entities.
13 * Deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0. We cannot
14 * use the deprecated PHPDoc tag because this service class is still used in
15 * legacy code paths. Symfony would fail test cases with deprecation warnings.
17 * @todo Enforce the deprecation of each method once
18 * https://www.drupal.org/node/2578361 is in.
20 class EntityManager implements EntityManagerInterface, ContainerAwareInterface {
22 use ContainerAwareTrait;
27 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
28 * Use \Drupal\Core\Entity\EntityTypeManagerInterface::clearCachedDefinitions()
31 * @see https://www.drupal.org/node/2549139
33 public function clearCachedDefinitions() {
34 $this->container->get('entity_type.manager')->clearCachedDefinitions();
36 // @todo None of these are plugin managers, and they should not co-opt
37 // this method for managing its caches. Remove in
38 // https://www.drupal.org/node/2549143.
39 $this->container->get('entity_type.bundle.info')->clearCachedBundles();
40 $this->container->get('entity_field.manager')->clearCachedFieldDefinitions();
41 $this->container->get('entity_type.repository')->clearCachedDefinitions();
47 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
48 * Use \Drupal\Core\Entity\EntityTypeManagerInterface::getDefinition()
51 * @see https://www.drupal.org/node/2549139
53 public function getDefinition($entity_type_id, $exception_on_invalid = TRUE) {
54 return $this->container->get('entity_type.manager')->getDefinition($entity_type_id, $exception_on_invalid);
60 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
61 * Use \Drupal\Core\Entity\EntityTypeManagerInterface::hasHandler()
64 * @see https://www.drupal.org/node/2549139
66 public function hasHandler($entity_type, $handler_type) {
67 return $this->container->get('entity_type.manager')->hasHandler($entity_type, $handler_type);
73 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
74 * Use \Drupal\Core\Entity\EntityTypeManagerInterface::getStorage() instead.
76 * @see https://www.drupal.org/node/2549139
78 public function getStorage($entity_type) {
79 return $this->container->get('entity_type.manager')->getStorage($entity_type);
85 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
86 * Use \Drupal\Core\Entity\EntityTypeManagerInterface::getListBuilder()
89 * @see https://www.drupal.org/node/2549139
91 public function getListBuilder($entity_type) {
92 return $this->container->get('entity_type.manager')->getListBuilder($entity_type);
98 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
99 * Use \Drupal\Core\Entity\EntityTypeManagerInterface::getFormObject()
102 * @see https://www.drupal.org/node/2549139
104 public function getFormObject($entity_type, $operation) {
105 return $this->container->get('entity_type.manager')->getFormObject($entity_type, $operation);
111 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
112 * Use \Drupal\Core\Entity\EntityTypeManagerInterface::getRouteProviders()
115 * @see https://www.drupal.org/node/2549139
117 public function getRouteProviders($entity_type) {
118 return $this->container->get('entity_type.manager')->getRouteProviders($entity_type);
124 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
125 * Use \Drupal\Core\Entity\EntityTypeManagerInterface::getViewBuilder()
128 * @see https://www.drupal.org/node/2549139
130 public function getViewBuilder($entity_type) {
131 return $this->container->get('entity_type.manager')->getViewBuilder($entity_type);
137 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
138 * Use \Drupal\Core\Entity\EntityTypeManagerInterface::getAccessControlHandler()
141 * @see https://www.drupal.org/node/2549139
143 public function getAccessControlHandler($entity_type) {
144 return $this->container->get('entity_type.manager')->getAccessControlHandler($entity_type);
150 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
151 * Use \Drupal\Core\Entity\EntityTypeManagerInterface::getHandler() instead.
153 * @see https://www.drupal.org/node/2549139
155 public function getHandler($entity_type, $handler_type) {
156 return $this->container->get('entity_type.manager')->getHandler($entity_type, $handler_type);
162 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
163 * Use \Drupal\Core\Entity\EntityTypeManagerInterface::createHandlerInstance()
166 * @see https://www.drupal.org/node/2549139
168 public function createHandlerInstance($class, EntityTypeInterface $definition = NULL) {
169 return $this->container->get('entity_type.manager')->createHandlerInstance($class, $definition);
175 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
176 * Use \Drupal\Core\Entity\EntityFieldManagerInterface::getBaseFieldDefinitions()
179 * @see https://www.drupal.org/node/2549139
181 public function getBaseFieldDefinitions($entity_type_id) {
182 return $this->container->get('entity_field.manager')->getBaseFieldDefinitions($entity_type_id);
188 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
189 * Use \Drupal\Core\Entity\EntityFieldManagerInterface::getFieldDefinitions()
192 * @see https://www.drupal.org/node/2549139
194 public function getFieldDefinitions($entity_type_id, $bundle) {
195 return $this->container->get('entity_field.manager')->getFieldDefinitions($entity_type_id, $bundle);
201 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
202 * Use \Drupal\Core\Entity\EntityFieldManagerInterface::getFieldStorageDefinitions()
205 * @see https://www.drupal.org/node/2549139
207 public function getFieldStorageDefinitions($entity_type_id) {
208 return $this->container->get('entity_field.manager')->getFieldStorageDefinitions($entity_type_id);
214 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
215 * Use \Drupal\Core\Entity\EntityFieldManagerInterface::setFieldMap()
218 * @see https://www.drupal.org/node/2549139
220 public function setFieldMap(array $field_map) {
221 return $this->container->get('entity_field.manager')->setFieldMap($field_map);
227 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
228 * Use \Drupal\Core\Entity\EntityFieldManagerInterface::getFieldMap()
231 * @see https://www.drupal.org/node/2549139
233 public function getFieldMap() {
234 return $this->container->get('entity_field.manager')->getFieldMap();
240 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
241 * Use \Drupal\Core\Entity\EntityFieldManagerInterface::getFieldMapByFieldType()
244 * @see https://www.drupal.org/node/2549139
246 public function getFieldMapByFieldType($field_type) {
247 return $this->container->get('entity_field.manager')->getFieldMapByFieldType($field_type);
253 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
254 * Use \Drupal\Core\Field\FieldDefinitionListenerInterface::onFieldDefinitionCreate()
257 * @see https://www.drupal.org/node/2549139
259 public function onFieldDefinitionCreate(FieldDefinitionInterface $field_definition) {
260 $this->container->get('field_definition.listener')->onFieldDefinitionCreate($field_definition);
266 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
267 * Use \Drupal\Core\Field\FieldDefinitionListenerInterface::onFieldDefinitionUpdate()
270 * @see https://www.drupal.org/node/2549139
272 public function onFieldDefinitionUpdate(FieldDefinitionInterface $field_definition, FieldDefinitionInterface $original) {
273 $this->container->get('field_definition.listener')->onFieldDefinitionUpdate($field_definition, $original);
279 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
280 * Use \Drupal\Core\Field\FieldDefinitionListenerInterface::onFieldDefinitionDelete()
283 * @see https://www.drupal.org/node/2549139
285 public function onFieldDefinitionDelete(FieldDefinitionInterface $field_definition) {
286 $this->container->get('field_definition.listener')->onFieldDefinitionDelete($field_definition);
292 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
293 * Use \Drupal\Core\Entity\EntityFieldManagerInterface::clearCachedFieldDefinitions()
296 * @see https://www.drupal.org/node/2549139
298 public function clearCachedFieldDefinitions() {
299 $this->container->get('entity_field.manager')->clearCachedFieldDefinitions();
305 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
306 * Use \Drupal\Core\Entity\EntityTypeBundleManagerInterface::clearCachedBundles()
309 * @see https://www.drupal.org/node/2549139
311 public function clearCachedBundles() {
312 $this->container->get('entity_type.bundle.info')->clearCachedBundles();
318 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
319 * Use \Drupal\Core\Entity\EntityTypeBundleManagerInterface::getBundleInfo()
322 * @see https://www.drupal.org/node/2549139
324 public function getBundleInfo($entity_type) {
325 return $this->container->get('entity_type.bundle.info')->getBundleInfo($entity_type);
331 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
332 * Use \Drupal\Core\Entity\EntityTypeBundleManagerInterface::getAllBundleInfo()
335 * @see https://www.drupal.org/node/2549139
337 public function getAllBundleInfo() {
338 return $this->container->get('entity_type.bundle.info')->getAllBundleInfo();
344 public function getExtraFields($entity_type_id, $bundle) {
345 return $this->container->get('entity_field.manager')->getExtraFields($entity_type_id, $bundle);
351 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
352 * Use \Drupal\Core\Entity\EntityTypeRepositoryInterface::getEntityTypeLabels()
355 * @see https://www.drupal.org/node/2549139
357 public function getEntityTypeLabels($group = FALSE) {
358 return $this->container->get('entity_type.repository')->getEntityTypeLabels($group);
364 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
365 * Use \Drupal\Core\Entity\EntityRepositoryInterface::getTranslationFromContext()
368 * @see https://www.drupal.org/node/2549139
370 public function getTranslationFromContext(EntityInterface $entity, $langcode = NULL, $context = []) {
371 return $this->container->get('entity.repository')->getTranslationFromContext($entity, $langcode, $context);
377 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
378 * Use \Drupal\Core\Entity\EntityDisplayRepositoryInterface::getAllViewModes()
381 * @see https://www.drupal.org/node/2549139
383 public function getAllViewModes() {
384 return $this->container->get('entity_display.repository')->getAllViewModes();
390 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
391 * Use \Drupal\Core\Entity\EntityDisplayRepositoryInterface::getViewModes()
394 * @see https://www.drupal.org/node/2549139
396 public function getViewModes($entity_type_id) {
397 return $this->container->get('entity_display.repository')->getViewModes($entity_type_id);
403 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
404 * Use \Drupal\Core\Entity\EntityDisplayRepositoryInterface::getAllFormModes()
407 * @see https://www.drupal.org/node/2549139
409 public function getAllFormModes() {
410 return $this->container->get('entity_display.repository')->getAllFormModes();
416 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
417 * Use \Drupal\Core\Entity\EntityDisplayRepositoryInterface::getFormModes()
420 * @see https://www.drupal.org/node/2549139
422 public function getFormModes($entity_type_id) {
423 return $this->container->get('entity_display.repository')->getFormModes($entity_type_id);
429 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
430 * Use \Drupal\Core\Entity\EntityDisplayRepositoryInterface::getViewModeOptions()
433 * @see https://www.drupal.org/node/2549139
435 public function getViewModeOptions($entity_type_id) {
436 return $this->container->get('entity_display.repository')->getViewModeOptions($entity_type_id);
442 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
443 * Use \Drupal\Core\Entity\EntityDisplayRepositoryInterface::getFormModeOptions()
446 * @see https://www.drupal.org/node/2549139
448 public function getFormModeOptions($entity_type_id) {
449 return $this->container->get('entity_display.repository')->getFormModeOptions($entity_type_id);
455 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
456 * Use \Drupal\Core\Entity\EntityDisplayRepositoryInterface::getViewModeOptionsByBundle()
459 * @see https://www.drupal.org/node/2549139
461 public function getViewModeOptionsByBundle($entity_type_id, $bundle) {
462 return $this->container->get('entity_display.repository')->getViewModeOptionsByBundle($entity_type_id, $bundle);
468 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
469 * Use \Drupal\Core\Entity\EntityDisplayRepositoryInterface::getFormModeOptionsByBundle()
472 * @see https://www.drupal.org/node/2549139
474 public function getFormModeOptionsByBundle($entity_type_id, $bundle) {
475 return $this->container->get('entity_display.repository')->getFormModeOptionsByBundle($entity_type_id, $bundle);
481 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
482 * Use \Drupal\Core\Entity\EntityDisplayRepositoryInterface::clearDisplayModeInfo()
485 * @see https://www.drupal.org/node/2549139
487 public function clearDisplayModeInfo() {
488 $this->container->get('entity_display.repository')->clearDisplayModeInfo();
494 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
495 * Use \Drupal\Core\Entity\EntityRepositoryInterface::loadEntityByUuid()
498 * @see https://www.drupal.org/node/2549139
500 public function loadEntityByUuid($entity_type_id, $uuid) {
501 return $this->container->get('entity.repository')->loadEntityByUuid($entity_type_id, $uuid);
507 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
508 * Use \Drupal\Core\Entity\EntityRepositoryInterface::loadEntityByConfigTarget()
511 * @see https://www.drupal.org/node/2549139
513 public function loadEntityByConfigTarget($entity_type_id, $target) {
514 return $this->container->get('entity.repository')->loadEntityByConfigTarget($entity_type_id, $target);
520 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
521 * Use \Drupal\Core\Entity\EntityTypeRepositoryInterface::getEntityTypeFromClass()
524 * @see https://www.drupal.org/node/2549139
526 public function getEntityTypeFromClass($class_name) {
527 return $this->container->get('entity_type.repository')->getEntityTypeFromClass($class_name);
533 public function onEntityTypeCreate(EntityTypeInterface $entity_type) {
534 $this->container->get('entity_type.listener')->onEntityTypeCreate($entity_type);
540 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
541 * Use \Drupal\Core\Entity\EntityTypeListenerInterface::onEntityTypeUpdate()
544 * @see https://www.drupal.org/node/2549139
546 public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original) {
547 $this->container->get('entity_type.listener')->onEntityTypeUpdate($entity_type, $original);
553 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
554 * Use \Drupal\Core\Entity\EntityTypeListenerInterface::onEntityTypeDelete()
557 * @see https://www.drupal.org/node/2549139
559 public function onEntityTypeDelete(EntityTypeInterface $entity_type) {
560 $this->container->get('entity_type.listener')->onEntityTypeDelete($entity_type);
566 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
567 * Use \Drupal\Core\Field\FieldStorageDefinitionListenerInterface::onFieldStorageDefinitionCreate()
570 * @see https://www.drupal.org/node/2549139
572 public function onFieldStorageDefinitionCreate(FieldStorageDefinitionInterface $storage_definition) {
573 $this->container->get('field_storage_definition.listener')->onFieldStorageDefinitionCreate($storage_definition);
579 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
580 * Use \Drupal\Core\Field\FieldStorageDefinitionListenerInterface::onFieldStorageDefinitionUpdate()
583 * @see https://www.drupal.org/node/2549139
585 public function onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) {
586 $this->container->get('field_storage_definition.listener')->onFieldStorageDefinitionUpdate($storage_definition, $original);
592 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
593 * Use \Drupal\Core\Field\FieldStorageDefinitionListenerInterface::onFieldStorageDefinitionDelete()
596 * @see https://www.drupal.org/node/2549139
598 public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $storage_definition) {
599 $this->container->get('field_storage_definition.listener')->onFieldStorageDefinitionDelete($storage_definition);
605 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
606 * Use \Drupal\Core\Entity\EntityBundleListenerInterface::onBundleCreate()
609 * @see https://www.drupal.org/node/2549139
611 public function onBundleCreate($bundle, $entity_type_id) {
612 $this->container->get('entity_bundle.listener')->onBundleCreate($bundle, $entity_type_id);
618 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
619 * Use \Drupal\Core\Entity\EntityBundleListenerInterface::onBundleDelete()
622 * @see https://www.drupal.org/node/2549139
624 public function onBundleDelete($bundle, $entity_type_id) {
625 $this->container->get('entity_bundle.listener')->onBundleDelete($bundle, $entity_type_id);
631 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
632 * Use \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface::getLastInstalledDefinition()
635 * @see https://www.drupal.org/node/2549139
637 public function getLastInstalledDefinition($entity_type_id) {
638 return $this->container->get('entity.last_installed_schema.repository')->getLastInstalledDefinition($entity_type_id);
644 public function useCaches($use_caches = FALSE) {
645 $this->container->get('entity_type.manager')->useCaches($use_caches);
647 // @todo EntityFieldManager is not a plugin manager, and should not co-opt
648 // this method for managing its caches.
649 $this->container->get('entity_field.manager')->useCaches($use_caches);
655 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
656 * Use \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface::getLastInstalledFieldStorageDefinitions()
659 * @see https://www.drupal.org/node/2549139
661 public function getLastInstalledFieldStorageDefinitions($entity_type_id) {
662 return $this->container->get('entity.last_installed_schema.repository')->getLastInstalledFieldStorageDefinitions($entity_type_id);
668 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
669 * Use \Drupal\Core\Entity\EntityTypeManagerInterface::getDefinitions()
672 * @see https://www.drupal.org/node/2549139
674 public function getDefinitions() {
675 return $this->container->get('entity_type.manager')->getDefinitions();
681 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
682 * Use \Drupal\Core\Entity\EntityTypeManagerInterface::hasDefinition()
685 * @see https://www.drupal.org/node/2549139
687 public function hasDefinition($plugin_id) {
688 return $this->container->get('entity_type.manager')->hasDefinition($plugin_id);
694 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
695 * Use \Drupal\Core\Entity\EntityTypeManagerInterface::createInstance()
698 * @see https://www.drupal.org/node/2549139
700 public function createInstance($plugin_id, array $configuration = []) {
701 return $this->container->get('entity_type.manager')->createInstance($plugin_id, $configuration);
707 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
708 * Use \Drupal\Core\Entity\EntityTypeManagerInterface::getInstance()
711 * @see https://www.drupal.org/node/2549139
713 public function getInstance(array $options) {
714 return $this->container->get('entity_type.manager')->getInstance($options);