diff --git a/core/lib/Drupal/Core/Entity/EntityFieldManagerInterface.php b/core/lib/Drupal/Core/Entity/EntityFieldManagerInterface.php index 26ed59e..3acfd10 100644 --- a/core/lib/Drupal/Core/Entity/EntityFieldManagerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityFieldManagerInterface.php @@ -109,10 +109,10 @@ public function clearCachedFieldDefinitions(); /** * Disable the use of caches. * - * This will also remove all local/static caches. - * * @param bool $use_caches * FALSE to not use any caches. + * + * @deprecated */ public function useCaches($use_caches = FALSE); diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index e4d5a89..8bc7fd5 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -16,7 +16,7 @@ use Drupal\Core\TypedData\TranslatableInterface; /** - * Provides helper functionality around entity fields. + * Provides a wrapper around many other services relating to entities. */ class EntityManager implements EntityManagerInterface { @@ -146,8 +146,12 @@ public function __construct(LanguageManagerInterface $language_manager, EntityTy */ public function clearCachedDefinitions() { $this->entityTypeManager->clearCachedDefinitions(); - $this->clearCachedBundles(); - $this->clearCachedFieldDefinitions(); + + // @todo None of these are plugin managers, and they should not co-opt + // this method for managing its caches. + $this->entityTypeBundleManager->clearCachedBundles(); + $this->entityFieldManager->clearCachedFieldDefinitions(); + $this->entityTypeRepository->clearCachedDefinitions(); } /** @@ -590,6 +594,9 @@ public function getLastInstalledDefinition($entity_type_id) { */ public function useCaches($use_caches = FALSE) { $this->entityTypeManager->useCaches($use_caches); + + // @todo EntityFieldManager is not a plugin manager, and should not co-opt + // this method for managing its caches. $this->entityFieldManager->useCaches($use_caches); } diff --git a/core/lib/Drupal/Core/Entity/EntityTypeManager.php b/core/lib/Drupal/Core/Entity/EntityTypeManager.php index 712460f..31d9fc3 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeManager.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeManager.php @@ -42,6 +42,20 @@ class EntityTypeManager extends DefaultPluginManager implements EntityTypeManage protected $handlers = []; /** + * The string translation service. + * + * @var \Drupal\Core\StringTranslation\TranslationInterface + */ + protected $stringTranslation; + + /** + * The class resolver. + * + * @var \Drupal\Core\DependencyInjection\ClassResolverInterface + */ + protected $classResolver; + + /** * Constructs a new Entity plugin manager. * * @param \Traversable $namespaces @@ -51,19 +65,19 @@ class EntityTypeManager extends DefaultPluginManager implements EntityTypeManage * The module handler. * @param \Drupal\Core\Cache\CacheBackendInterface $cache * The cache backend to use. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager - * The string translationManager. + * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation + * The string translation. * @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver * The class resolver. */ - public function __construct(\Traversable $namespaces, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, TranslationInterface $translation_manager, ClassResolverInterface $class_resolver) { + public function __construct(\Traversable $namespaces, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, TranslationInterface $string_translation, ClassResolverInterface $class_resolver) { parent::__construct('Entity', $namespaces, $module_handler, 'Drupal\Core\Entity\EntityInterface'); $this->setCacheBackend($cache, 'entity_type', ['entity_types']); $this->alterInfo('entity_type'); $this->discovery = new AnnotatedClassDiscovery('Entity', $namespaces, 'Drupal\Core\Entity\Annotation\EntityType'); - $this->translationManager = $translation_manager; + $this->stringTranslation = $string_translation; $this->classResolver = $class_resolver; } @@ -122,7 +136,6 @@ public function getDefinition($entity_type_id, $exception_on_invalid = TRUE) { public function clearCachedDefinitions() { parent::clearCachedDefinitions(); $this->handlers = []; - $this->classNameEntityTypeMap = []; } /** @@ -172,7 +185,7 @@ public function getFormObject($entity_type, $operation) { $form_object = $this->classResolver->getInstanceFromDefinition($class); $form_object - ->setStringTranslation($this->translationManager) + ->setStringTranslation($this->stringTranslation) ->setModuleHandler($this->moduleHandler) ->setEntityTypeManager($this) ->setOperation($operation) @@ -244,7 +257,7 @@ public function createHandlerInstance($class, EntityTypeInterface $definition = $handler->setModuleHandler($this->moduleHandler); } if (method_exists($handler, 'setStringTranslation')) { - $handler->setStringTranslation($this->translationManager); + $handler->setStringTranslation($this->stringTranslation); } return $handler; diff --git a/core/lib/Drupal/Core/Entity/EntityTypeRepository.php b/core/lib/Drupal/Core/Entity/EntityTypeRepository.php index 23ae537..0ad9cab 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeRepository.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeRepository.php @@ -141,4 +141,11 @@ public function getEntityTypeFromClass($class_name) { throw new NoCorrespondingEntityClassException($class_name); } + /** + * {@inheritdoc} + */ + public function clearCachedDefinitions() { + $this->classNameEntityTypeMap = []; + } + } diff --git a/core/lib/Drupal/Core/Entity/EntityTypeRepositoryInterface.php b/core/lib/Drupal/Core/Entity/EntityTypeRepositoryInterface.php index b004fdc..8c7a1d7 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeRepositoryInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeRepositoryInterface.php @@ -86,4 +86,11 @@ public function getEntityTypeLabels($group = FALSE); */ public function getEntityTypeFromClass($class_name); + /** + * Clear the static cache. + * + * @deprecated + */ + public function clearCachedDefinitions(); + }