diff --git a/core/lib/Drupal/Core/Condition/ConditionManager.php b/core/lib/Drupal/Core/Condition/ConditionManager.php index 2f4c060..9788311 100644 --- a/core/lib/Drupal/Core/Condition/ConditionManager.php +++ b/core/lib/Drupal/Core/Condition/ConditionManager.php @@ -7,34 +7,14 @@ namespace Drupal\Core\Condition; -use Drupal\Component\Plugin\PluginManagerBase; -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\Plugin\Discovery\AlterDecorator; -use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; -use Drupal\Core\Plugin\Discovery\CacheDecorator; +use Drupal\Core\Executable\ExecutableManagerInterface; +use Drupal\Core\Plugin\DefaultPluginManager; /** * A plugin manager for condition plugins. */ -class ConditionManager extends PluginManagerBase implements ExecutableManagerInterface { - - /** - * Constructs aa ConditionManager object. - * - * @param array $namespaces - * An array of paths keyed by it's corresponding namespaces. - */ - public function __construct(array $namespaces) { - $this->discovery = new AnnotatedClassDiscovery('Core', 'Condition', $namespaces); - $this->discovery = new DerivativeDiscoveryDecorator($this->discovery); - $this->discovery = new AlterDecorator($this->discovery, 'condition_info'); - $this->discovery = new CacheDecorator($this->discovery, 'condition:' . language(LANGUAGE_TYPE_INTERFACE)->langcode); - - $this->factory = new DefaultFactory($this); - } +class ConditionManager extends DefaultPluginManager implements ExecutableManagerInterface { /** * Override of Drupal\Component\Plugin\PluginManagerBase::createInstance(). diff --git a/core/lib/Drupal/Core/CoreBundle.php b/core/lib/Drupal/Core/CoreBundle.php index ba4e3ed..4cae9a4 100644 --- a/core/lib/Drupal/Core/CoreBundle.php +++ b/core/lib/Drupal/Core/CoreBundle.php @@ -142,7 +142,11 @@ public function build(ContainerBuilder $container) { // Register the EntityManager. $container->register('plugin.manager.entity', 'Drupal\Core\Entity\EntityManager') - ->addArgument('%container.namespaces%'); + ->addArgument('Core') + ->addArgument('Entity') + ->addArgument('%container.namespaces%') + ->addMethodCall('setAlterHook', array(new Reference('module_handler'), 'entity_info')) + ->addMethodCall('setCache', array(new Reference('cache.cache'), 'entity_info')); // The 'request' scope and service enable services to depend on the Request // object and get reconstructed when the request object changes (e.g., @@ -300,7 +304,12 @@ public function build(ContainerBuilder $container) { $container->register('flood', 'Drupal\Core\Flood\DatabaseBackend') ->addArgument(new Reference('database')); - $container->register('plugin.manager.condition', 'Drupal\Core\Condition\ConditionManager'); + $container->register('plugin.manager.condition', 'Drupal\Core\Condition\ConditionManager') + ->addArgument('Core') + ->addArgument('Condition') + ->addArgument('%container.namespaces%') + ->addMethodCall('setAlterHook', array(new Reference('module_handler'), 'condition_info')) + ->addMethodCall('setCache', array(new Reference('cache.cache'), 'condition')); $container->register('kernel_destruct_subscriber', 'Drupal\Core\EventSubscriber\KernelDestructionSubscriber') ->addMethodCall('setContainer', array(new Reference('service_container'))); diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index a0d7c03..73d847e 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -7,14 +7,7 @@ namespace Drupal\Core\Entity; -use Drupal\Component\Plugin\PluginManagerBase; -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; +use Drupal\Core\Plugin\DefaultPluginManager; /** * Manages entity type plugin definitions. @@ -133,7 +126,7 @@ * @see entity_get_info() * @see hook_entity_info_alter() */ -class EntityManager extends PluginManagerBase { +class EntityManager extends DefaultPluginManager { /** * Contains instantiated controllers keyed by controller type and entity type. @@ -167,23 +160,6 @@ class EntityManager extends PluginManagerBase { ); /** - * Constructs a new Entity plugin manager. - * - * @param array $namespaces - * An array of paths keyed by it's corresponding namespaces. - */ - public function __construct(array $namespaces) { - // Allow the plugin definition to be altered by hook_entity_info_alter(). - $this->discovery = new AnnotatedClassDiscovery('Core', 'Entity', $namespaces); - $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->discovery = new CacheDecorator($this->discovery, 'entity_info:' . language(LANGUAGE_TYPE_INTERFACE)->langcode, 'cache', CacheBackendInterface::CACHE_PERMANENT, array('entity_info' => TRUE)); - - $this->factory = new DefaultFactory($this->discovery); - } - - /** * Overrides Drupal\Component\Plugin\PluginManagerBase::processDefinition(). */ public function processDefinition(&$definition, $plugin_id) { diff --git a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php index 1ce3eca..08e3e4f 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php +++ b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php @@ -127,7 +127,7 @@ public function __construct($owner, $type, array $namespaces) { $this->discovery = new AnnotatedClassDiscovery($owner, $type, $namespaces); $this->discovery = new DerivativeDiscoveryDecorator($this->discovery); - $this->factory = new DefaultFactory($this->discovery); + $this->factory = new DefaultFactory($this); } /** @@ -189,6 +189,28 @@ public function processDefinition(&$definition, $plugin_id) { } /** + * Implements Drupal\Component\Plugin\Discovery\DicoveryInterface::getDefinition(). + */ + public function getDefinition($plugin_id) { + // Optimize for fast access to definitions if they are already in memory. + if (isset($this->definitions)) { + // Avoid using a ternary that would create a copy of the array. + if (isset($this->definitions[$plugin_id])) { + return $this->definitions[$plugin_id]; + } + else { + return; + } + } + + $definitions = $this->getDefinitions(); + // Avoid using a ternary that would create a copy of the array. + if (isset($definitions[$plugin_id])) { + return $definitions[$plugin_id]; + } + } + + /** * Implements \Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface::getDefinitions(). */ public function getDefinitions() { @@ -199,7 +221,7 @@ public function getDefinitions() { $this->processDefinition($definition, $plugin_id); } if ($this->alterHook) { - Drupal::service('module_handler')->alter($this->alterHook, $definitions); + $this->moduleHandler->alter($this->alterHook, $definitions); } $this->setCachedDefinitions($definitions); } @@ -244,7 +266,7 @@ protected function getCachedDefinitions() { */ protected function setCachedDefinitions($definitions) { if ($this->cache) { - $this->cache->set($this->cacheKey, $definitions, $this->cacheExpire, $this->cacheTags); + $this->cache->set($this->cacheKey, $definitions); } $this->definitions = $definitions; } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/AggregatorBundle.php b/core/modules/aggregator/lib/Drupal/aggregator/AggregatorBundle.php index 9c97d9a..081156b 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/AggregatorBundle.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/AggregatorBundle.php @@ -19,8 +19,11 @@ class AggregatorBundle extends Bundle { * Overrides Bundle::build(). */ public function build(ContainerBuilder $container) { - $container->register('plugin.manager.aggregator.fetcher', 'Drupal\aggregator\Plugin\FetcherManager') - ->addArgument('%container.namespaces%'); + $container->register('plugin.manager.aggregator.fetcher', 'Drupal\Core\Plugin\DefaultPluginManager') + ->addArgument('aggregator') + ->addArgument('fetcher') + ->addArgument('%container.namespaces%') + ->addMethodCall('setCache', array(new Reference('cache.cache'), 'aggregator_fetcher')); } } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/FetcherManager.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/FetcherManager.php deleted file mode 100644 index be8fc79..0000000 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/FetcherManager.php +++ /dev/null @@ -1,31 +0,0 @@ -discovery = new AnnotatedClassDiscovery('aggregator', 'fetcher', $namespaces); - $this->discovery = new CacheDecorator($this->discovery, 'aggregator_fetcher:' . language(LANGUAGE_TYPE_INTERFACE)->langcode); - $this->factory = new DefaultFactory($this->discovery); - } -} 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 cf2b8ef..890199c 100644 --- a/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php +++ b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php @@ -23,8 +23,8 @@ class BlockManager extends DefaultPluginManager { * Overrides \Drupal\Component\Plugin\PluginManagerBase::createInstance(). */ public function createInstance($plugin_id, array $configuration = array(), Block $entity = NULL) { - $plugin_class = DefaultFactory::getPluginClass($plugin_id, $this->discovery); - return new $plugin_class($configuration, $plugin_id, $this->discovery, $entity); + $plugin_class = DefaultFactory::getPluginClass($plugin_id, $this); + return new $plugin_class($configuration, $plugin_id, $this, $entity); } } diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php b/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php index 5500241..c6ffc12 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php @@ -7,32 +7,14 @@ namespace Drupal\ckeditor; -use Drupal\Component\Plugin\PluginManagerBase; -use Drupal\Component\Plugin\Factory\DefaultFactory; -use Drupal\Component\Plugin\Discovery\ProcessDecorator; use Drupal\Component\Utility\NestedArray; -use Drupal\Core\Plugin\Discovery\AlterDecorator; -use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; -use Drupal\Core\Plugin\Discovery\CacheDecorator; +use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\editor\Plugin\Core\Entity\Editor; /** * CKEditor Plugin manager. */ -class CKEditorPluginManager extends PluginManagerBase { - - /** - * Overrides \Drupal\Component\Plugin\PluginManagerBase::__construct(). - * - * @param array $namespaces - * An array of paths keyed by it's corresponding namespaces. - */ - public function __construct(array $namespaces) { - $this->discovery = new AnnotatedClassDiscovery('ckeditor', 'plugin', $namespaces); - $this->discovery = new AlterDecorator($this->discovery, 'ckeditor_plugin_info'); - $this->discovery = new CacheDecorator($this->discovery, 'ckeditor_plugin'); - $this->factory = new DefaultFactory($this->discovery); - } +class CKEditorPluginManager extends DefaultPluginManager { /** * Determines which plug-ins are enabled. diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/CkeditorBundle.php b/core/modules/ckeditor/lib/Drupal/ckeditor/CkeditorBundle.php index 151c23a..52fc191 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/CkeditorBundle.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/CkeditorBundle.php @@ -21,7 +21,11 @@ class CKEditorBundle extends Bundle { */ public function build(ContainerBuilder $container) { $container->register('plugin.manager.ckeditor.plugin', 'Drupal\ckeditor\CKEditorPluginManager') - ->addArgument('%container.namespaces%'); + ->addArgument('ckeditor') + ->addArgument('plugin') + ->addArgument('%container.namespaces%') + ->addMethodCall('setAlterHook', array(new Reference('module_handler'), 'ckeditor_plugin_info')) + ->addMethodCall('setCache', array(new Reference('cache.cache'), 'ckeditor_plugin')); } } diff --git a/core/modules/edit/lib/Drupal/edit/EditBundle.php b/core/modules/edit/lib/Drupal/edit/EditBundle.php index fe52594..e393fb2 100644 --- a/core/modules/edit/lib/Drupal/edit/EditBundle.php +++ b/core/modules/edit/lib/Drupal/edit/EditBundle.php @@ -20,8 +20,12 @@ class EditBundle extends Bundle { * Overrides Symfony\Component\HttpKernel\Bundle\Bundle::build(). */ public function build(ContainerBuilder $container) { - $container->register('plugin.manager.edit.editor', 'Drupal\edit\Plugin\EditorManager') - ->addArgument('%container.namespaces%'); + $container->register('plugin.manager.edit.editor', 'Drupal\Core\Plugin\DefaultPluginManager') + ->addArgument('edit') + ->addArgument('editor') + ->addArgument('%container.namespaces%') + ->addMethodCall('setAlterHook', array(new Reference('module_handler'), 'edit_editor')) + ->addMethodCall('setCache', array(new Reference('cache.cache'), 'edit:editor')); $container->register('access_check.edit.entity_field', 'Drupal\edit\Access\EditEntityFieldAccessCheck') ->addTag('access_check'); diff --git a/core/modules/edit/lib/Drupal/edit/Plugin/EditorManager.php b/core/modules/edit/lib/Drupal/edit/Plugin/EditorManager.php deleted file mode 100644 index ce2d650..0000000 --- a/core/modules/edit/lib/Drupal/edit/Plugin/EditorManager.php +++ /dev/null @@ -1,51 +0,0 @@ -discovery = new AnnotatedClassDiscovery('edit', 'editor', $namespaces); - $this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition')); - $this->discovery = new AlterDecorator($this->discovery, 'edit_editor'); - $this->discovery = new CacheDecorator($this->discovery, 'edit:editor'); - $this->factory = new DefaultFactory($this->discovery); - } - - /** - * Overrides \Drupal\Component\Plugin\PluginManagerBase::processDefinition(). - */ - public function processDefinition(&$definition, $plugin_id) { - parent::processDefinition($definition, $plugin_id); - - // @todo Remove this check once http://drupal.org/node/1780396 is resolved. - if (!module_exists($definition['module'])) { - $definition = NULL; - return; - } - } - -} diff --git a/core/modules/editor/lib/Drupal/editor/EditorBundle.php b/core/modules/editor/lib/Drupal/editor/EditorBundle.php index 0338998..2687485 100644 --- a/core/modules/editor/lib/Drupal/editor/EditorBundle.php +++ b/core/modules/editor/lib/Drupal/editor/EditorBundle.php @@ -22,7 +22,11 @@ public function build(ContainerBuilder $container) { // Register the plugin manager for our plugin type with the dependency // injection container. $container->register('plugin.manager.editor', 'Drupal\editor\Plugin\EditorManager') - ->addArgument('%container.namespaces%'); + ->addArgument('editor') + ->addArgument('editor') + ->addArgument('%container.namespaces%') + ->addMethodCall('setAlterHook', array(new Reference('module_handler'), 'editor_info')) + ->addMethodCall('setCache', array(new Reference('cache.cache'), 'editor')); } } diff --git a/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php b/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php index c267b5f..27cc1e3 100644 --- a/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php +++ b/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php @@ -7,30 +7,12 @@ namespace Drupal\editor\Plugin; -use Drupal\Component\Plugin\PluginManagerBase; -use Drupal\Component\Plugin\Factory\DefaultFactory; -use Drupal\Component\Plugin\Discovery\ProcessDecorator; -use Drupal\Core\Plugin\Discovery\AlterDecorator; -use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; -use Drupal\Core\Plugin\Discovery\CacheDecorator; +use Drupal\Core\Plugin\DefaultPluginManager; /** * Configurable text editor manager. */ -class EditorManager extends PluginManagerBase { - - /** - * Overrides \Drupal\Component\Plugin\PluginManagerBase::__construct(). - * - * @param array $namespaces - * An array of paths keyed by it's corresponding namespaces. - */ - public function __construct(array $namespaces) { - $this->discovery = new AnnotatedClassDiscovery('editor', 'editor', $namespaces); - $this->discovery = new AlterDecorator($this->discovery, 'editor_info'); - $this->discovery = new CacheDecorator($this->discovery, 'editor'); - $this->factory = new DefaultFactory($this->discovery); - } +class EditorManager extends DefaultPluginManager { /** * Populates a key-value pair of available text editors. diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceBundle.php b/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceBundle.php index 56bd797..ecb9901 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceBundle.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceBundle.php @@ -22,6 +22,10 @@ public function build(ContainerBuilder $container) { // Register the SelectionPluginManager class with the dependency injection // container. $container->register('plugin.manager.entity_reference.selection', 'Drupal\entity_reference\Plugin\Type\SelectionPluginManager') - ->addArgument('%container.namespaces%'); + ->addArgument('entity_reference') + ->addArgument('selection') + ->addArgument('%container.namespaces%') + ->addMethodCall('setAlterHook', array(new Reference('module_handler'))) + ->addMethodCall('setCache', array(new Reference('cache.cache'), 'entity_reference_selection')); } } diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php index db3bd47..8e1ae27 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php @@ -9,16 +9,13 @@ use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Component\Plugin\Factory\ReflectionFactory; -use Drupal\Component\Plugin\PluginManagerBase; -use Drupal\Core\Plugin\Discovery\AlterDecorator; -use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; -use Drupal\Core\Plugin\Discovery\CacheDecorator; +use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\entity_reference\Plugin\Type\Selection\SelectionBroken; /** * Plugin type manager for the Entity Reference Selection plugin. */ -class SelectionPluginManager extends PluginManagerBase { +class SelectionPluginManager extends DefaultPluginManager { /** * Constructs a SelectionPluginManager object. @@ -26,9 +23,8 @@ class SelectionPluginManager extends PluginManagerBase { * @param array $namespaces * An array of paths keyed by it's corresponding namespaces. */ - public function __construct($namespaces) { - $this->baseDiscovery = new AlterDecorator(new AnnotatedClassDiscovery('entity_reference', 'selection', $namespaces), 'entity_reference_selection'); - $this->discovery = new CacheDecorator($this->baseDiscovery, 'entity_reference_selection'); + public function __construct($owner, $type, array $namespaces) { + parent::__construct($owner, $type, $namespaces); $this->factory = new ReflectionFactory($this); } diff --git a/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/DefaultsTestPluginManager.php b/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/DefaultsTestPluginManager.php index f62fcc9..96693c2 100644 --- a/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/DefaultsTestPluginManager.php +++ b/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/DefaultsTestPluginManager.php @@ -7,15 +7,14 @@ namespace Drupal\plugin_test\Plugin; -use Drupal\Component\Plugin\PluginManagerBase; use Drupal\Component\Plugin\Discovery\StaticDiscovery; -use Drupal\Component\Plugin\Discovery\ProcessDecorator; use Drupal\Component\Plugin\Factory\DefaultFactory; +use Drupal\Core\Plugin\DefaultPluginManager; /** * Defines a plugin manager used by Plugin API unit tests. */ -class DefaultsTestPluginManager extends PluginManagerBase { +class DefaultsTestPluginManager extends DefaultPluginManager { public function __construct() { // Create the object that can be used to return definitions for all the @@ -23,7 +22,6 @@ public function __construct() { // discovery implementation, but StaticDiscovery lets us add some simple // mock plugins for unit testing. $this->discovery = new StaticDiscovery(); - $this->discovery = new ProcessDecorator($this->discovery, array($this, 'ProcessDefinition')); $this->factory = new DefaultFactory($this->discovery); // Specify default values. diff --git a/core/modules/tour/lib/Drupal/tour/TipPluginManager.php b/core/modules/tour/lib/Drupal/tour/TipPluginManager.php deleted file mode 100644 index f4a1016..0000000 --- a/core/modules/tour/lib/Drupal/tour/TipPluginManager.php +++ /dev/null @@ -1,34 +0,0 @@ -discovery = new AnnotatedClassDiscovery('tour', 'tip', $namespaces); - $this->discovery = new CacheDecorator($this->discovery, 'tour'); - - $this->factory = new DefaultFactory($this->discovery); - } - -} diff --git a/core/modules/tour/lib/Drupal/tour/TourBundle.php b/core/modules/tour/lib/Drupal/tour/TourBundle.php index bb50299..af18093 100644 --- a/core/modules/tour/lib/Drupal/tour/TourBundle.php +++ b/core/modules/tour/lib/Drupal/tour/TourBundle.php @@ -21,8 +21,11 @@ class TourBundle extends Bundle { public function build(ContainerBuilder $container) { // Register the plugin manager for our plugin type with the dependency // injection container. - $container->register('plugin.manager.tour.tip', 'Drupal\tour\TipPluginManager') - ->addArgument('%container.namespaces%'); + $container->register('plugin.manager.tour.tip', 'Drupal\Core\Plugin\DefaultPluginManager') + ->addArgument('tour') + ->addArgument('tip') + ->addArgument('%container.namespaces%') + ->addMethodCall('setCache', array(new Reference('cache.cache'), 'tour')); } }