diff --git a/core/lib/Drupal/Component/Plugin/Discovery/ProcessDecorator.php b/core/lib/Drupal/Component/Plugin/Discovery/ProcessDecorator.php deleted file mode 100644 index 1a881230d87..00000000000 --- a/core/lib/Drupal/Component/Plugin/Discovery/ProcessDecorator.php +++ /dev/null @@ -1,70 +0,0 @@ -decorated = $decorated; - $this->processCallback = $process_callback; - } - - /** - * Implements \Drupal\Component\Plugin\Discovery\DicoveryInterface::getDefinitions(). - */ - public function getDefinitions() { - $definitions = $this->decorated->getDefinitions(); - foreach ($definitions as $plugin_id => &$definition) { - call_user_func_array($this->processCallback, array(&$definition, $plugin_id)); - } - // Allow process callbacks to unset definitions. - return array_filter($definitions); - } - - /** - * Passes through all unknown calls onto the decorated object. - */ - public function __call($method, $args) { - return call_user_func_array(array($this->decorated, $method), $args); - } - -} diff --git a/core/lib/Drupal/Component/Plugin/PluginManagerBase.php b/core/lib/Drupal/Component/Plugin/PluginManagerBase.php index f3a19b04420..201b2070ef5 100644 --- a/core/lib/Drupal/Component/Plugin/PluginManagerBase.php +++ b/core/lib/Drupal/Component/Plugin/PluginManagerBase.php @@ -7,13 +7,12 @@ namespace Drupal\Component\Plugin; -use Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface; use Drupal\Component\Plugin\Discovery\DiscoveryTrait; /** * Base class for plugin managers. */ -abstract class PluginManagerBase implements PluginManagerInterface, CachedDiscoveryInterface { +abstract class PluginManagerBase implements PluginManagerInterface { use DiscoveryTrait; @@ -52,15 +51,6 @@ abstract class PluginManagerBase implements PluginManagerInterface, CachedDiscov return $this->discovery->getDefinitions(); } - /** - * {@inheritdoc} - */ - public function clearCachedDefinitions() { - if ($this->discovery instanceof CachedDiscoveryInterface) { - $this->discovery->clearCachedDefinitions(); - } - } - /** * {@inheritdoc} */ diff --git a/core/lib/Drupal/Core/Menu/LocalActionManager.php b/core/lib/Drupal/Core/Menu/LocalActionManager.php index fc252b1d39e..456b749ebcf 100644 --- a/core/lib/Drupal/Core/Menu/LocalActionManager.php +++ b/core/lib/Drupal/Core/Menu/LocalActionManager.php @@ -10,11 +10,8 @@ namespace Drupal\Core\Menu; use Drupal\Core\Access\AccessManager; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Language\LanguageManager; use Drupal\Core\Language\LanguageManagerInterface; -use Drupal\Core\Menu\LocalActionInterface; use Drupal\Core\Plugin\DefaultPluginManager; -use Drupal\Component\Plugin\Discovery\ProcessDecorator; use Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator; use Drupal\Core\Plugin\Discovery\YamlDiscovery; use Drupal\Core\Plugin\Factory\ContainerFactory; diff --git a/core/lib/Drupal/Core/Plugin/Discovery/AlterDecorator.php b/core/lib/Drupal/Core/Plugin/Discovery/AlterDecorator.php deleted file mode 100644 index 0a7cf861854..00000000000 --- a/core/lib/Drupal/Core/Plugin/Discovery/AlterDecorator.php +++ /dev/null @@ -1,64 +0,0 @@ -decorated = $decorated; - $this->hook = $hook; - } - - /** - * Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinitions(). - */ - public function getDefinitions() { - $definitions = $this->decorated->getDefinitions(); - \Drupal::moduleHandler()->alter($this->hook, $definitions); - return $definitions; - } - - /** - * Passes through all unknown calls onto the decorated object. - */ - public function __call($method, $args) { - return call_user_func_array(array($this->decorated, $method), $args); - } -} diff --git a/core/lib/Drupal/Core/Plugin/Discovery/CacheDecorator.php b/core/lib/Drupal/Core/Plugin/Discovery/CacheDecorator.php deleted file mode 100644 index 9fd21460515..00000000000 --- a/core/lib/Drupal/Core/Plugin/Discovery/CacheDecorator.php +++ /dev/null @@ -1,157 +0,0 @@ -decorated = $decorated; - $this->cacheKey = $cache_key; - $this->cacheBin = $cache_bin; - $this->cacheExpire = $cache_expire; - $this->cacheTags = $cache_tags; - } - - /** - * Implements Drupal\Component\Plugin\Discovery\DicoveryInterface::getDefinitions(). - */ - public function getDefinitions() { - // Optimize for fast access to definitions if they are already in memory. - if (isset($this->definitions)) { - return $this->definitions; - } - - $definitions = $this->getCachedDefinitions(); - if (!isset($definitions)) { - $definitions = $this->decorated->getDefinitions(); - $this->setCachedDefinitions($definitions); - } - return $definitions; - } - - /** - * Returns the cached plugin definitions of the decorated discovery class. - * - * @return mixed - * On success this will return an array of plugin definitions. On failure - * this should return NULL, indicating to other methods that this has not - * yet been defined. Success with no values should return as an empty array - * and would actually be returned by the getDefinitions() method. - */ - protected function getCachedDefinitions() { - if (!isset($this->definitions) && isset($this->cacheKey) && $cache = $this->cache($this->cacheBin)->get($this->cacheKey)) { - $this->definitions = $cache->data; - } - return $this->definitions; - } - - /** - * Sets a cache of plugin definitions for the decorated discovery class. - * - * @param array $definitions - * List of definitions to store in cache. - */ - protected function setCachedDefinitions($definitions) { - if (isset($this->cacheKey)) { - $this->cache($this->cacheBin)->set($this->cacheKey, $definitions, $this->cacheExpire, $this->cacheTags); - } - $this->definitions = $definitions; - } - - /** - * Implements \Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface::clearCachedDefinitions(). - */ - public function clearCachedDefinitions() { - // If there are any cache tags, clear cache based on those. - if (!empty($this->cacheTags)) { - Cache::deleteTags($this->cacheTags); - } - // Otherwise, just delete the specified cache key. - else if (isset($this->cacheKey)) { - $this->cache($this->cacheBin)->delete($this->cacheKey); - } - $this->definitions = NULL; - } - - /** - * Passes through all unknown calls onto the decorated object. - */ - public function __call($method, $args) { - return call_user_func_array(array($this->decorated, $method), $args); - } - - /** - * Wraps the \Drupal::cache() method. - */ - protected function cache($bin) { - return \Drupal::cache($bin); - } - -} diff --git a/core/lib/Drupal/Core/Validation/ConstraintManager.php b/core/lib/Drupal/Core/Validation/ConstraintManager.php index 94eed864d03..a2b46d30728 100644 --- a/core/lib/Drupal/Core/Validation/ConstraintManager.php +++ b/core/lib/Drupal/Core/Validation/ConstraintManager.php @@ -107,7 +107,7 @@ class ConstraintManager extends DefaultPluginManager { } /** - * Process definition callback for the ProcessDecorator. + * {@inheritdoc} */ public function processDefinition(&$definition, $plugin_id) { // Make sure 'type' is set and either an array or FALSE. diff --git a/core/modules/system/src/Tests/Plugin/AlterDecoratorTest.php b/core/modules/system/src/Tests/Plugin/AlterDecoratorTest.php deleted file mode 100644 index b6946f354af..00000000000 --- a/core/modules/system/src/Tests/Plugin/AlterDecoratorTest.php +++ /dev/null @@ -1,56 +0,0 @@ -alterTestPluginManager = new AlterDecoratorTestPluginManager(); - } - - /** - * Tests getDefinitions() and getDefinition() of Drupal\Core\Plugin\Discovery\AlterDecorator. - */ - public function testAlterDecorator() { - // Ensure that getDefinitions() fires and changes the actual plugin definitions. - $definitions = $this->alterTestPluginManager->getDefinitions(); - foreach ($definitions as &$definition) { - $this->assertTrue($definition['altered']); - } - - // Ensure that getDefinitions() fires and changes the actual plugin definition. - $definition = $this->alterTestPluginManager->getDefinition('user_login'); - $this->assertTrue($definition['altered_single']); - } - -} diff --git a/core/modules/system/src/Tests/Plugin/CacheDecoratorLanguageTest.php b/core/modules/system/src/Tests/Plugin/CacheDecoratorLanguageTest.php deleted file mode 100644 index 6be2b6f6256..00000000000 --- a/core/modules/system/src/Tests/Plugin/CacheDecoratorLanguageTest.php +++ /dev/null @@ -1,121 +0,0 @@ -mockBlockExpectedDefinitions = array( - 'user_login' => array( - 'label' => 'User login', - 'class' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\MockUserLoginBlock', - ), - 'menu:main_menu' => array( - 'label' => 'Main menu', - 'class' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\MockMenuBlock', - ), - 'menu:navigation' => array( - 'label' => 'Navigation', - 'class' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\MockMenuBlock', - ), - 'layout' => array( - 'label' => 'Layout', - 'class' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\MockLayoutBlock', - ), - 'layout:foo' => array( - 'label' => 'Layout Foo', - 'class' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\MockLayoutBlock', - ), - ); - - // Create two languages: Spanish and German. - $this->languages = array('de', 'es'); - foreach ($this->languages as $langcode) { - $language = new Language(array('id' => $langcode)); - $languages[$langcode] = language_save($language); - // Set up translations for each mock block label. - $custom_strings = array(); - foreach ($this->mockBlockExpectedDefinitions as $definition) { - $custom_strings[$definition['label']] = $langcode . ' ' . $definition['label']; - } - $this->addCustomTranslations($langcode, array('' => $custom_strings)); - $this->rebuildContainer(); - } - // Write test settings.php with new translations. - $this->writeCustomTranslations(); - } - - /** - * Check the translations of the cached plugin definitions. - */ - public function testCacheDecoratorLanguage() { - $languages = $this->languages; - $this->drupalGet('plugin_definition_test'); - foreach ($this->mockBlockExpectedDefinitions as $definition) { - // Find our source text. - $this->assertText($definition['label']); - } - foreach ($languages as $langcode) { - $url = $langcode . '/plugin_definition_test'; - // For each language visit the language specific version of the page again. - $this->drupalGet($url); - foreach ($this->mockBlockExpectedDefinitions as $definition) { - // Find our provided translations. - $label = $langcode . ' ' . $definition['label']; - $this->assertText($label); - } - } - // Manually check that the expected cache keys are present. - $languages[] = 'en'; - foreach ($languages as $langcode) { - $cache = \Drupal::cache()->get('mock_block:' . $langcode); - $this->assertEqual($cache->cid, 'mock_block:' . $langcode, format_string('The !cache cache exists.', array('!cache' => 'mock_block:' . $langcode))); - $this->assertEqual($cache->expire, 1542646800, format_string('The cache expiration was properly set.')); - } - // Clear the plugin definitions. - $manager = new CachedMockBlockManager(); - $manager->clearCachedDefinitions(); - foreach ($languages as $langcode) { - $cache = \Drupal::cache()->get('mock_block:' . $langcode); - $this->assertFalse($cache, format_string('The !cache cache was properly cleared through the cache::deleteTags() method.', array('!cache' => 'mock_block:' . $langcode))); - } - // Change the translations for the german language and recheck strings. - $custom_strings = array(); - foreach ($this->mockBlockExpectedDefinitions as $definition) { - $custom_strings[$definition['label']] = $definition['label'] . ' de'; - } - $this->addCustomTranslations('de', array('' => $custom_strings)); - $this->writeCustomTranslations(); - $this->drupalGet('de/plugin_definition_test'); - foreach ($this->mockBlockExpectedDefinitions as $definition) { - // Find our provided translations. - $label = $definition['label'] . ' de'; - $this->assertText($label); - } - } - -} diff --git a/core/modules/system/src/Tests/Plugin/CacheDecoratorTest.php b/core/modules/system/src/Tests/Plugin/CacheDecoratorTest.php deleted file mode 100644 index 99f2d81be13..00000000000 --- a/core/modules/system/src/Tests/Plugin/CacheDecoratorTest.php +++ /dev/null @@ -1,131 +0,0 @@ -set("cache.$this->cacheBin", new MemoryBackend($this->cacheBin)); - - // Create discovery objects to test. - $this->emptyDiscovery = new StaticDiscovery(); - $this->emptyDiscovery = new CacheDecorator($this->emptyDiscovery, $this->cacheKey . '_empty', $this->cacheBin); - - $this->discovery = new StaticDiscovery(); - $this->discovery = new CacheDecorator($this->discovery, $this->cacheKey, $this->cacheBin); - - // Populate sample definitions. - $this->expectedDefinitions = array( - 'apple' => array( - 'label' => 'Apple', - 'color' => 'green', - ), - 'cherry' => array( - 'label' => 'Cherry', - 'color' => 'red', - ), - 'orange' => array( - 'label' => 'Orange', - 'color' => 'orange', - ), - ); - foreach ($this->expectedDefinitions as $plugin_id => $definition) { - $this->discovery->setDefinition($plugin_id, $definition); - } - } - - /** - * Tests that discovered definitions are properly cached. - * - * This comes in addition to DiscoveryTestBase::testDiscoveryInterface(), - * that test the basic discovery behavior. - */ - public function testCachedDefinitions() { - $cache = \Drupal::cache($this->cacheBin); - - // Check that nothing is cached initially. - $cached = $cache->get($this->cacheKey); - $this->assertIdentical($cached, FALSE, 'Cache is empty.'); - - // Get the definitions once, and check that they are present in the cache. - $definitions = $this->discovery->getDefinitions(); - $this->assertIdentical($definitions, $this->expectedDefinitions, 'Definitions are correctly retrieved.'); - $cached = $cache->get($this->cacheKey); - $this->assertIdentical($cached->data, $this->expectedDefinitions, 'Definitions are cached.'); - - // Check that the definitions are also cached in memory. Since the - // CacheDecorator::definitions property is protected, this is tested "from - // the outside" by wiping the cache entry, getting the definitions, and - // checking that the cache entry was not regenerated (thus showing that - // defintions were not fetched from the decorated discovery). - $cache->delete($this->cacheKey); - $definitions = $this->discovery->getDefinitions(); - $cached = $cache->get($this->cacheKey); - $this->assertIdentical($cached, FALSE, 'Cache is empty.'); - $this->assertIdentical($definitions, $this->expectedDefinitions, 'Definitions are cached in memory.'); - } - - /** - * Tests CacheDecorator::clearCachedDefinitions(). - */ - public function testClearCachedDefinitions() { - $cache = \Drupal::cache($this->cacheBin); - - // Populate the caches by collecting definitions once. - $this->discovery->getDefinitions(); - - // Add a new definition. - $this->expectedDefinitions['banana'] = array( - 'label' => 'Banana', - 'color' => 'yellow', - ); - $this->discovery->setDefinition('banana', $this->expectedDefinitions['banana']); - - // Check that the new definition is not found. - $definition = $this->discovery->getDefinition('banana', FALSE); - $this->assertNull($definition, 'Newly added definition is not found.'); - - // Clear cached definitions, and check that the new definition is found. - $this->discovery->clearCachedDefinitions(); - $cached = $cache->get($this->cacheKey); - $this->assertIdentical($cached, FALSE, 'Cache is empty.'); - $definitions = $this->discovery->getDefinitions(); - $this->assertIdentical($definitions, $this->expectedDefinitions, 'Newly added definition is found.'); - } - -} diff --git a/core/modules/system/tests/modules/plugin_test/plugin_test.routing.yml b/core/modules/system/tests/modules/plugin_test/plugin_test.routing.yml deleted file mode 100644 index 228e7697100..00000000000 --- a/core/modules/system/tests/modules/plugin_test/plugin_test.routing.yml +++ /dev/null @@ -1,6 +0,0 @@ -plugin_test.definition: - path: '/plugin_definition_test' - defaults: - _content: '\Drupal\plugin_test\Controller\PluginTest::testDefinitions' - requirements: - _access: 'TRUE' diff --git a/core/modules/system/tests/modules/plugin_test/src/Controller/PluginTest.php b/core/modules/system/tests/modules/plugin_test/src/Controller/PluginTest.php deleted file mode 100644 index 5ec7fa41ec1..00000000000 --- a/core/modules/system/tests/modules/plugin_test/src/Controller/PluginTest.php +++ /dev/null @@ -1,34 +0,0 @@ -getDefinitions() as $plugin_id => $definition) { - $output[$plugin_id] = array( - '#markup' => $definition['label'], - ); - } - return $output; - } - -} diff --git a/core/modules/system/tests/modules/plugin_test/src/Plugin/AlterDecoratorTestPluginManager.php b/core/modules/system/tests/modules/plugin_test/src/Plugin/AlterDecoratorTestPluginManager.php deleted file mode 100644 index 2168b8beab6..00000000000 --- a/core/modules/system/tests/modules/plugin_test/src/Plugin/AlterDecoratorTestPluginManager.php +++ /dev/null @@ -1,20 +0,0 @@ -discovery = new AlterDecorator($this->discovery, 'plugin_test'); - } -} diff --git a/core/modules/system/tests/modules/plugin_test/src/Plugin/CachedMockBlockManager.php b/core/modules/system/tests/modules/plugin_test/src/Plugin/CachedMockBlockManager.php deleted file mode 100644 index 4eb2aee3957..00000000000 --- a/core/modules/system/tests/modules/plugin_test/src/Plugin/CachedMockBlockManager.php +++ /dev/null @@ -1,29 +0,0 @@ -discovery = new CacheDecorator($this->discovery, 'mock_block:' . \Drupal::languageManager()->getCurrentLanguage()->id, 'default', 1542646800, array('plugin_test')); - } -}