diff --git a/core/includes/common.inc b/core/includes/common.inc index f3d8f2c64e2cb02a65aed66294b864d6fdb3ed6a..63cc8a7e66d9a5cde7a177e58f1a33a9343555d7 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -6430,7 +6430,8 @@ function drupal_flush_all_caches() { drupal_static_reset(); // Clear all non-drupal_static() static caches. - // None currently; kept if any static caches need to be reset in the future. + // @todo Rebuild the kernel/container. + drupal_container()->get('plugin.manager.entity')->clearCachedDefinitions(); // Rebuild module and theme data. system_rebuild_module_data(); diff --git a/core/includes/entity.inc b/core/includes/entity.inc index 4ae754beebc657d3b6efd38db6bbbdeaf16002a5..a686ec6247ca711f15a1623622446166197ac27f 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -23,24 +23,15 @@ * * @see \Drupal\Core\Entity\EntityManager * @see hook_entity_info_alter() + * + * @deprecated Use \Drupal\Core\Entity\EntityManager::getDefinitions() directly. */ function entity_get_info($entity_type = NULL) { - // Use the advanced drupal_static() pattern, since this is called very often. - static $drupal_static_fast; - if (!isset($drupal_static_fast)) { - $drupal_static_fast['entity_info'] = &drupal_static(__FUNCTION__); - } - $entity_info = &$drupal_static_fast['entity_info']; - - if (empty($entity_info)) { - $entity_info = drupal_container()->get('plugin.manager.entity')->getDefinitions(); - } - if (empty($entity_type)) { - return $entity_info; + return drupal_container()->get('plugin.manager.entity')->getDefinitions(); } - elseif (isset($entity_info[$entity_type])) { - return $entity_info[$entity_type]; + else { + return drupal_container()->get('plugin.manager.entity')->getDefinition($entity_type); } } @@ -48,11 +39,10 @@ function entity_get_info($entity_type = NULL) { * Resets the cached information about entity types. */ function entity_info_cache_clear() { - drupal_static_reset('entity_get_info'); drupal_static_reset('entity_get_view_modes'); drupal_static_reset('entity_get_bundles'); // Clear all languages. - cache()->deleteTags(array('entity_info' => TRUE)); + drupal_container()->get('plugin.manager.entity')->clearCachedDefinitions(); } /** diff --git a/core/lib/Drupal/Component/Plugin/Discovery/CachedDiscoveryInterface.php b/core/lib/Drupal/Component/Plugin/Discovery/CachedDiscoveryInterface.php index 27aa039c47f0d5160b5f0559a356d6d4d49c66cc..fc070247458bada3af0e8106e312f7e144cdd952 100644 --- a/core/lib/Drupal/Component/Plugin/Discovery/CachedDiscoveryInterface.php +++ b/core/lib/Drupal/Component/Plugin/Discovery/CachedDiscoveryInterface.php @@ -13,7 +13,7 @@ interface CachedDiscoveryInterface extends DiscoveryInterface { /** - * Clears cached plugin definitions. + * Clears static and persistent plugin definition caches. */ public function clearCachedDefinitions(); diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index c760707834a8245e1a78248178ff4bec1ce6a1f6..739ccbc6b960bba2959f64dd56f09ef3965432b6 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -11,6 +11,7 @@ use Drupal\Component\Plugin\Factory\DefaultFactory; use Drupal\Component\Plugin\Discovery\ProcessDecorator; use Drupal\Core\Plugin\Discovery\AlterDecorator; +use Drupal\Core\Plugin\Discovery\CacheDecorator; use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; use Drupal\Core\Plugin\Discovery\InfoHookDecorator; use Drupal\Core\Cache\CacheBackendInterface; @@ -129,34 +130,6 @@ */ class EntityManager extends PluginManagerBase { - /** - * The cache bin used for entity plugin definitions. - * - * @var string - */ - protected $cacheBin = 'cache'; - - /** - * The cache key used for entity plugin definitions. - * - * @var string - */ - protected $cacheKey = 'entity_info'; - - /** - * The cache expiration for entity plugin definitions. - * - * @var int - */ - protected $cacheExpire = CacheBackendInterface::CACHE_PERMANENT; - - /** - * The cache tags used for entity plugin definitions. - * - * @var array - */ - protected $cacheTags = array('entity_info' => TRUE); - /** * Contains instantiated controllers keyed by controller type and entity type. * @@ -197,36 +170,9 @@ public function __construct() { $this->discovery = new InfoHookDecorator($this->discovery, 'entity_info'); $this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition')); $this->discovery = new AlterDecorator($this->discovery, 'entity_info'); - $this->factory = new DefaultFactory($this); + $this->discovery = new CacheDecorator($this->discovery, 'entity_info:' . language(LANGUAGE_TYPE_INTERFACE)->langcode, 'cache', CacheBackendInterface::CACHE_PERMANENT, array('entity_info' => TRUE)); - // Entity type plugins includes translated strings, so each language is - // cached separately. - $this->cacheKey .= ':' . language(LANGUAGE_TYPE_INTERFACE)->langcode; - } - - /** - * Overrides Drupal\Component\Plugin\PluginManagerBase::getDefinition(). - */ - public function getDefinition($plugin_id) { - $definitions = $this->getDefinitions(); - return isset($definitions[$plugin_id]) ? $definitions[$plugin_id] : NULL; - } - - /** - * Overrides Drupal\Component\Plugin\PluginManagerBase::getDefinitions(). - */ - public function getDefinitions() { - // Because \Drupal\Core\Plugin\Discovery\CacheDecorator runs before - // definitions are processed and does not support cache tags, we perform our - // own caching. - if ($cache = cache($this->cacheBin)->get($this->cacheKey)) { - return $cache->data; - } - else { - $definitions = parent::getDefinitions(); - cache($this->cacheBin)->set($this->cacheKey, $definitions, $this->cacheExpire, $this->cacheTags); - return $definitions; - } + $this->factory = new DefaultFactory($this->discovery); } /** diff --git a/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSettingsTest.php b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSettingsTest.php index 80d4202513553812c83d43555ca09e04ab942468..41600acd4348f243563b50a1160c1de80b128760 100644 --- a/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSettingsTest.php +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSettingsTest.php @@ -115,7 +115,7 @@ protected function assertSettings($entity_type, $bundle, $enabled, $edit) { $this->drupalPost('admin/config/regional/content-language', $edit, t('Save')); $args = array('@entity_type' => $entity_type, '@bundle' => $bundle, '@enabled' => $enabled ? 'enabled' : 'disabled'); $message = format_string('Translation for entity @entity_type (@bundle) is @enabled.', $args); - drupal_static_reset(); + entity_info_cache_clear(); return $this->assertEqual(translation_entity_enabled($entity_type, $bundle), $enabled, $message); }