diff --git a/core/core.services.yml b/core/core.services.yml index f744d1a..70f5799 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -153,10 +153,7 @@ services: arguments: ['@container.namespaces'] plugin.manager.archiver: class: Drupal\Core\Archiver\ArchiverManager - arguments: ['@container.namespaces'] - calls: - - [setAlterHook, ['@module_handler', 'archiver_info']] - - [setCache, ['@cache.cache', 'archiver_info']] + arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@module_handler'] request: class: Symfony\Component\HttpFoundation\Request event_dispatcher: @@ -181,10 +178,7 @@ services: - [setValidationConstraintManager, ['@validation.constraint']] validation.constraint: class: Drupal\Core\Validation\ConstraintManager - arguments: ['@container.namespaces'] - calls: - - [setAlterHook, ['@module_handler', 'validation_constraint']] - - [setCache, ['@cache.cache', 'validation_constraint']] + arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@module_handler'] lock: class: Drupal\Core\Lock\DatabaseLockBackend user.tempstore: @@ -409,10 +403,7 @@ services: arguments: ['@database', '@request'] plugin.manager.condition: class: Drupal\Core\Condition\ConditionManager - arguments: ['@container.namespaces'] - calls: - - [setAlterHook, ['@module_handler', 'condition_info']] - - [setCache, ['@cache.cache', 'condition']] + arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@module_handler'] kernel_destruct_subscriber: class: Drupal\Core\EventSubscriber\KernelDestructionSubscriber tags: @@ -425,9 +416,7 @@ services: - { name: event_subscriber } image.toolkit.manager: class: Drupal\system\Plugin\ImageToolkitManager - arguments: ['@container.namespaces'] - calls: - - [setCache, ['@cache.cache', 'image_toolkit']] + arguments: ['@container.namespaces', '@cache.cache', '@language_manager'] image.toolkit: class: Drupal\system\Plugin\ImageToolkitInterface factory_method: getDefaultToolkit diff --git a/core/lib/Drupal/Core/Archiver/ArchiverManager.php b/core/lib/Drupal/Core/Archiver/ArchiverManager.php index 51a3ff8..a37ea2b 100644 --- a/core/lib/Drupal/Core/Archiver/ArchiverManager.php +++ b/core/lib/Drupal/Core/Archiver/ArchiverManager.php @@ -8,6 +8,7 @@ use Drupal\Component\Plugin\Factory\DefaultFactory; use Drupal\Core\Plugin\DefaultPluginManager; + /** * Archiver plugin manager. */ @@ -19,9 +20,19 @@ class ArchiverManager extends DefaultPluginManager { * @param \Traversable $namespaces * An object that implements \Traversable which contains the root paths * keyed by the corresponding namespace to look for plugin implementations, + * @param \Drupal\Core\Cache\CacheBackendInterface $cache + * Cache backend instance to use. + * @param \Drupal\Core\Language\LanguageManager + * The language manager. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler to invoke the alter hook with. */ - public function __construct(\Traversable $namespaces) { + public function __construct(\Traversable $namespaces, CacheBackendInterfac $cache, LanguageManager $language_manager, ModuleHandler $module_handler) { parent::__construct('Archiver', $namespaces); + $this->discovery = new StaticDiscoveryDecorator($this->discovery, array($this, 'registerDefinitions')); + $this->alterHook = 'archiver_info'; + $this->moduleHandler = $module_handler; + $this->setCache($cache, $language_manager, 'archiver_info'); } /** diff --git a/core/lib/Drupal/Core/Condition/ConditionManager.php b/core/lib/Drupal/Core/Condition/ConditionManager.php index 2675a29..1ecd709 100644 --- a/core/lib/Drupal/Core/Condition/ConditionManager.php +++ b/core/lib/Drupal/Core/Condition/ConditionManager.php @@ -7,18 +7,12 @@ namespace Drupal\Core\Condition; -use Drupal\Component\Plugin\PluginManagerBase; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Executable\ExecutableManagerInterface; use Drupal\Core\Executable\ExecutableInterface; -use Drupal\Component\Plugin\Factory\DefaultFactory; -use Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\LanguageManager; use Drupal\Core\Plugin\DefaultPluginManager; -use Drupal\Core\Plugin\Discovery\AlterDecorator; -use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; -use Drupal\Core\Plugin\Discovery\CacheDecorator; /** * A plugin manager for condition plugins. diff --git a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php index ed1c6cb..f189f95 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php +++ b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php @@ -194,6 +194,7 @@ protected function setCachedDefinitions($definitions) { * Finds plugin definitions. * * @return array + * List of definitions to store in cache. */ protected function findDefinitions() { $definitions = $this->discovery->getDefinitions(); diff --git a/core/lib/Drupal/Core/Validation/ConstraintManager.php b/core/lib/Drupal/Core/Validation/ConstraintManager.php index 2a1719f..14e44a1 100644 --- a/core/lib/Drupal/Core/Validation/ConstraintManager.php +++ b/core/lib/Drupal/Core/Validation/ConstraintManager.php @@ -8,7 +8,9 @@ namespace Drupal\Core\Validation; use Drupal\Component\Plugin\Discovery\StaticDiscoveryDecorator; -use Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator; +use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Extension\ModuleHandler; +use Drupal\Core\Language\LanguageManager; use Drupal\Core\Plugin\DefaultPluginManager; /** @@ -37,11 +39,19 @@ class ConstraintManager extends DefaultPluginManager { * @param \Traversable $namespaces * An object that implements \Traversable which contains the root paths * keyed by the corresponding namespace to look for plugin implementations, + * @param \Drupal\Core\Cache\CacheBackendInterface $cache + * Cache backend instance to use. + * @param \Drupal\Core\Language\LanguageManager + * The language manager. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler to invoke the alter hook with. */ - public function __construct(\Traversable $namespaces) { + public function __construct(\Traversable $namespaces, CacheBackendInterface $cache, LanguageManager $language_manager, ModuleHandler $module_handler) { parent::__construct('Validation/Constraint', $namespaces); $this->discovery = new StaticDiscoveryDecorator($this->discovery, array($this, 'registerDefinitions')); - $this->discovery = new DerivativeDiscoveryDecorator($this->discovery); + $this->alterHook = 'validation_constraint'; + $this->moduleHandler = $module_handler; + $this->setCache($cache, $language_manager, 'validation_constraint'); } /** diff --git a/core/modules/block/block.services.yml b/core/modules/block/block.services.yml index 5c14a02..6e87ce2 100644 --- a/core/modules/block/block.services.yml +++ b/core/modules/block/block.services.yml @@ -1,10 +1,7 @@ services: plugin.manager.block: class: Drupal\block\Plugin\Type\BlockManager - arguments: ['@container.namespaces'] - calls: - - [setAlterHook, ['@module_handler', 'block']] - - [setCache, ['@cache.block', 'block_plugins']] + arguments: ['@container.namespaces', '@cache.block', '@language_manager', '@module_handler'] cache.block: class: Drupal\Core\Cache\CacheBackendInterface tags: diff --git a/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php index 6c098c7..4b393ee 100644 --- a/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php +++ b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php @@ -24,8 +24,17 @@ class BlockManager extends DefaultPluginManager { * @param \Traversable $namespaces * An object that implements \Traversable which contains the root paths * keyed by the corresponding namespace to look for plugin implementations, + * @param \Drupal\Core\Cache\CacheBackendInterface $cache + * Cache backend instance to use. + * @param \Drupal\Core\Language\LanguageManager + * The language manager. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler to invoke the alter hook with. */ - public function __construct(\Traversable $namespaces) { + public function __construct(\Traversable $namespaces, CacheBackendInterfac $cache, LanguageManager $language_manager, ModuleHandler $module_handler) { parent::__construct('Block', $namespaces); + $this->alterHook = 'block'; + $this->moduleHandler = $module_handler; + $this->setCache($cache, $language_manager, 'block_plugins'); } } diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitManager.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitManager.php index 7f9af89..47872f9 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitManager.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitManager.php @@ -7,6 +7,8 @@ namespace Drupal\system\Plugin; +use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Language\LanguageManager; use Drupal\Core\Plugin\DefaultPluginManager; /** @@ -20,9 +22,12 @@ class ImageToolkitManager extends DefaultPluginManager { * @param \Traversable $namespaces * An object that implements \Traversable which contains the root paths * keyed by the corresponding namespace to look for plugin implementations, + * @param \Drupal\Core\Cache\CacheBackendInterface $cache + * Cache backend instance to use. */ - public function __construct(\Traversable $namespaces) { + public function __construct(\Traversable $namespaces, CacheBackendInterface $cache, LanguageManager $language_manager) { parent::__construct('ImageToolkit', $namespaces); + $this->setCache($cache, $language_manager, 'image_toolkit'); } /** diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php index 4a91541..18d6f51 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php @@ -70,18 +70,6 @@ function setUp() { ), 'class' => 'Drupal\plugin_test\Plugin\plugin_test\fruit\Banana', ), - 'cherry' => array( - 'id' => 'cherry', - 'label' => 'Cherry', - 'color' => 'red', - 'class' => 'Drupal\plugin_test\Plugin\plugin_test\fruit\Cherry', - ), - 'orange' => array( - 'id' => 'orange', - 'label' => 'Orange', - 'color' => 'orange', - 'class' => 'Drupal\plugin_test\Plugin\plugin_test\fruit\Orange', - ), ); $this->namespaces = $namespaces = new \ArrayObject(array('Drupal\plugin_test' => DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib')); @@ -91,7 +79,7 @@ function setUp() { * Tests the plugin manager with no cache and altering. */ function testDefaultPluginManager() { - $plugin_manager = new TestDefaultPluginManager($this->namespaces); + $plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions); $this->assertEquals($this->expectedDefinitions, $plugin_manager->getDefinitions()); } @@ -107,7 +95,7 @@ function testDefaultPluginManagerWithAlter() { ->method('alter') ->with($this->equalTo($alter_hook_name), $this->equalTo($this->expectedDefinitions)); - $plugin_manager = new TestDefaultPluginManager($this->namespaces); + $plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions); $plugin_manager->setAlterHook($module_handler, $alter_hook_name); $this->assertEquals($this->expectedDefinitions, $plugin_manager->getDefinitions()); @@ -138,7 +126,7 @@ function testDefaultPluginManagerWithEmptyCache() { ->with(LANGUAGE_TYPE_INTERFACE) ->will($this->returnValue($language)); - $plugin_manager = new TestDefaultPluginManager($this->namespaces); + $plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions); $plugin_manager->setCache($cache_backend, $language_manager, $cid); $this->assertEquals($this->expectedDefinitions, $plugin_manager->getDefinitions()); @@ -168,7 +156,7 @@ function testDefaultPluginManagerWithFilledCache() { ->with(LANGUAGE_TYPE_INTERFACE) ->will($this->returnValue($language)); - $plugin_manager = new TestDefaultPluginManager($this->namespaces); + $plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions); $plugin_manager->setCache($cache_backend, $language_manager, $cid); $this->assertEquals($this->expectedDefinitions, $plugin_manager->getDefinitions()); diff --git a/core/tests/Drupal/Tests/Core/Plugin/TestDefaultPluginManager.php b/core/tests/Drupal/Tests/Core/Plugin/TestPluginManager.php similarity index 62% rename from core/tests/Drupal/Tests/Core/Plugin/TestDefaultPluginManager.php rename to core/tests/Drupal/Tests/Core/Plugin/TestPluginManager.php index 6bb7de2..0f97c00 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/TestDefaultPluginManager.php +++ b/core/tests/Drupal/Tests/Core/Plugin/TestPluginManager.php @@ -7,13 +7,14 @@ namespace Drupal\Tests\Core\Plugin; +use Drupal\Component\Plugin\Discovery\StaticDiscovery; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\DefaultPluginManager; /** * A plugin manager for condition plugins. */ -class TestDefaultPluginManager extends DefaultPluginManager { +class TestPluginManager extends DefaultPluginManager { /** * Constructs aa ConditionManager object. @@ -22,8 +23,17 @@ class TestDefaultPluginManager extends DefaultPluginManager { * An object that implements \Traversable which contains the root paths * keyed by the corresponding namespace to look for plugin implementations, */ - public function __construct(\Traversable $namespaces) { - parent::__construct('plugin_test/fruit', $namespaces); + public function __construct(\Traversable $namespaces, $definitions) { + // Create the object that can be used to return definitions for all the + // plugins available for this type. Most real plugin managers use a richer + // discovery implementation, but StaticDiscovery lets us add some simple + // mock plugins for unit testing. + $this->discovery = new StaticDiscovery(); + + // Add the static definitions. + foreach ($definitions as $key => $definition) { + $this->discovery->setDefinition($key, $definition); + } } /** diff --git a/core/tests/bootstrap.php b/core/tests/bootstrap.php index bddeff0..36cd94e 100644 --- a/core/tests/bootstrap.php +++ b/core/tests/bootstrap.php @@ -27,17 +27,3 @@ // numbers handling. // @see drupal_environment_initialize() setlocale(LC_ALL, 'C'); - -/** - * Test replacement for the t() function. - * - * @param $string - * The string to translate. - * @param array $arguments - * Array of replacements. - * @param array $context - * Translation context, unused. - */ -function t($string, array $args = array(), array $context = array()) { - return String::format($string, $args); -}