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.
29 public function clearCachedDefinitions() {
30 $this->container->get('entity_type.manager')->clearCachedDefinitions();
32 // @todo None of these are plugin managers, and they should not co-opt
33 // this method for managing its caches. Remove in
34 // https://www.drupal.org/node/2549143.
35 $this->container->get('entity_type.bundle.info')->clearCachedBundles();
36 $this->container->get('entity_field.manager')->clearCachedFieldDefinitions();
37 $this->container->get('entity_type.repository')->clearCachedDefinitions();
43 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
45 public function getDefinition($entity_type_id, $exception_on_invalid = TRUE) {
46 return $this->container->get('entity_type.manager')->getDefinition($entity_type_id, $exception_on_invalid);
52 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
54 public function hasHandler($entity_type, $handler_type) {
55 return $this->container->get('entity_type.manager')->hasHandler($entity_type, $handler_type);
61 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
63 public function getStorage($entity_type) {
64 return $this->container->get('entity_type.manager')->getStorage($entity_type);
70 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
72 public function getListBuilder($entity_type) {
73 return $this->container->get('entity_type.manager')->getListBuilder($entity_type);
79 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
81 public function getFormObject($entity_type, $operation) {
82 return $this->container->get('entity_type.manager')->getFormObject($entity_type, $operation);
88 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
90 public function getRouteProviders($entity_type) {
91 return $this->container->get('entity_type.manager')->getRouteProviders($entity_type);
97 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
99 public function getViewBuilder($entity_type) {
100 return $this->container->get('entity_type.manager')->getViewBuilder($entity_type);
106 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
108 public function getAccessControlHandler($entity_type) {
109 return $this->container->get('entity_type.manager')->getAccessControlHandler($entity_type);
115 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
117 public function getHandler($entity_type, $handler_type) {
118 return $this->container->get('entity_type.manager')->getHandler($entity_type, $handler_type);
124 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
126 public function createHandlerInstance($class, EntityTypeInterface $definition = NULL) {
127 return $this->container->get('entity_type.manager')->createHandlerInstance($class, $definition);
133 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
135 public function getBaseFieldDefinitions($entity_type_id) {
136 return $this->container->get('entity_field.manager')->getBaseFieldDefinitions($entity_type_id);
142 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
144 public function getFieldDefinitions($entity_type_id, $bundle) {
145 return $this->container->get('entity_field.manager')->getFieldDefinitions($entity_type_id, $bundle);
151 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
153 public function getFieldStorageDefinitions($entity_type_id) {
154 return $this->container->get('entity_field.manager')->getFieldStorageDefinitions($entity_type_id);
160 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
162 public function setFieldMap(array $field_map) {
163 return $this->container->get('entity_field.manager')->setFieldMap($field_map);
169 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
171 public function getFieldMap() {
172 return $this->container->get('entity_field.manager')->getFieldMap();
178 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
180 public function getFieldMapByFieldType($field_type) {
181 return $this->container->get('entity_field.manager')->getFieldMapByFieldType($field_type);
187 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
189 public function onFieldDefinitionCreate(FieldDefinitionInterface $field_definition) {
190 $this->container->get('field_definition.listener')->onFieldDefinitionCreate($field_definition);
196 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
198 public function onFieldDefinitionUpdate(FieldDefinitionInterface $field_definition, FieldDefinitionInterface $original) {
199 $this->container->get('field_definition.listener')->onFieldDefinitionUpdate($field_definition, $original);
205 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
207 public function onFieldDefinitionDelete(FieldDefinitionInterface $field_definition) {
208 $this->container->get('field_definition.listener')->onFieldDefinitionDelete($field_definition);
214 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
216 public function clearCachedFieldDefinitions() {
217 $this->container->get('entity_field.manager')->clearCachedFieldDefinitions();
223 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
225 public function clearCachedBundles() {
226 $this->container->get('entity_type.bundle.info')->clearCachedBundles();
232 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
234 public function getBundleInfo($entity_type) {
235 return $this->container->get('entity_type.bundle.info')->getBundleInfo($entity_type);
241 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
243 public function getAllBundleInfo() {
244 return $this->container->get('entity_type.bundle.info')->getAllBundleInfo();
250 public function getExtraFields($entity_type_id, $bundle) {
251 return $this->container->get('entity_field.manager')->getExtraFields($entity_type_id, $bundle);
257 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
259 public function getEntityTypeLabels($group = FALSE) {
260 return $this->container->get('entity_type.repository')->getEntityTypeLabels($group);
266 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
268 public function getTranslationFromContext(EntityInterface $entity, $langcode = NULL, $context = []) {
269 return $this->container->get('entity.repository')->getTranslationFromContext($entity, $langcode, $context);
275 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
277 public function getAllViewModes() {
278 return $this->container->get('entity_display.repository')->getAllViewModes();
284 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
286 public function getViewModes($entity_type_id) {
287 return $this->container->get('entity_display.repository')->getViewModes($entity_type_id);
293 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
295 public function getAllFormModes() {
296 return $this->container->get('entity_display.repository')->getAllFormModes();
302 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
304 public function getFormModes($entity_type_id) {
305 return $this->container->get('entity_display.repository')->getFormModes($entity_type_id);
311 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
313 public function getViewModeOptions($entity_type_id) {
314 return $this->container->get('entity_display.repository')->getViewModeOptions($entity_type_id);
320 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
322 public function getFormModeOptions($entity_type_id) {
323 return $this->container->get('entity_display.repository')->getFormModeOptions($entity_type_id);
329 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
331 public function getViewModeOptionsByBundle($entity_type_id, $bundle) {
332 return $this->container->get('entity_display.repository')->getViewModeOptionsByBundle($entity_type_id, $bundle);
338 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
340 public function getFormModeOptionsByBundle($entity_type_id, $bundle) {
341 return $this->container->get('entity_display.repository')->getFormModeOptionsByBundle($entity_type_id, $bundle);
347 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
349 public function clearDisplayModeInfo() {
350 $this->container->get('entity_display.repository')->clearDisplayModeInfo();
356 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
358 public function loadEntityByUuid($entity_type_id, $uuid) {
359 return $this->container->get('entity.repository')->loadEntityByUuid($entity_type_id, $uuid);
365 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
367 public function loadEntityByConfigTarget($entity_type_id, $target) {
368 return $this->container->get('entity.repository')->loadEntityByConfigTarget($entity_type_id, $target);
374 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
376 public function getEntityTypeFromClass($class_name) {
377 return $this->container->get('entity_type.repository')->getEntityTypeFromClass($class_name);
383 public function onEntityTypeCreate(EntityTypeInterface $entity_type) {
384 $this->container->get('entity_type.listener')->onEntityTypeCreate($entity_type);
390 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
392 public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original) {
393 $this->container->get('entity_type.listener')->onEntityTypeUpdate($entity_type, $original);
399 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
401 public function onEntityTypeDelete(EntityTypeInterface $entity_type) {
402 $this->container->get('entity_type.listener')->onEntityTypeDelete($entity_type);
408 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
410 public function onFieldStorageDefinitionCreate(FieldStorageDefinitionInterface $storage_definition) {
411 $this->container->get('field_storage_definition.listener')->onFieldStorageDefinitionCreate($storage_definition);
417 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
419 public function onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) {
420 $this->container->get('field_storage_definition.listener')->onFieldStorageDefinitionUpdate($storage_definition, $original);
426 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
428 public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $storage_definition) {
429 $this->container->get('field_storage_definition.listener')->onFieldStorageDefinitionDelete($storage_definition);
435 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
437 public function onBundleCreate($bundle, $entity_type_id) {
438 $this->container->get('entity_bundle.listener')->onBundleCreate($bundle, $entity_type_id);
444 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
446 public function onBundleDelete($bundle, $entity_type_id) {
447 $this->container->get('entity_bundle.listener')->onBundleDelete($bundle, $entity_type_id);
453 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
455 public function getLastInstalledDefinition($entity_type_id) {
456 return $this->container->get('entity.last_installed_schema.repository')->getLastInstalledDefinition($entity_type_id);
462 public function useCaches($use_caches = FALSE) {
463 $this->container->get('entity_type.manager')->useCaches($use_caches);
465 // @todo EntityFieldManager is not a plugin manager, and should not co-opt
466 // this method for managing its caches.
467 $this->container->get('entity_field.manager')->useCaches($use_caches);
473 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
475 public function getLastInstalledFieldStorageDefinitions($entity_type_id) {
476 return $this->container->get('entity.last_installed_schema.repository')->getLastInstalledFieldStorageDefinitions($entity_type_id);
482 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
484 public function getDefinitions() {
485 return $this->container->get('entity_type.manager')->getDefinitions();
491 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
493 public function hasDefinition($plugin_id) {
494 return $this->container->get('entity_type.manager')->hasDefinition($plugin_id);
500 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
502 public function createInstance($plugin_id, array $configuration = []) {
503 return $this->container->get('entity_type.manager')->createInstance($plugin_id, $configuration);
509 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
511 public function getInstance(array $options) {
512 return $this->container->get('entity_type.manager')->getInstance($options);