Commit 428d0f0a authored by webchick's avatar webchick
Browse files

Issue #2053153 by tim.plunkett, dawehner, damiankloip, aspilicious: Allow...

Issue #2053153 by tim.plunkett, dawehner, damiankloip, aspilicious: Allow contrib modules to provide plugins on behalf of optional modules.
parent f0f543f0
......@@ -605,7 +605,7 @@ services:
- { name: event_subscriber }
image.toolkit.manager:
class: Drupal\Core\ImageToolkit\ImageToolkitManager
arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@config.factory']
arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@config.factory', '@module_handler']
image.toolkit:
class: Drupal\Core\ImageToolkit\ImageToolkitInterface
factory_method: getDefaultToolkit
......
......@@ -31,8 +31,8 @@ class ArchiverManager extends DefaultPluginManager {
* The module handler to invoke the alter hook with.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/Archiver', $namespaces, 'Drupal\Core\Archiver\Annotation\Archiver');
$this->alterInfo($module_handler, 'archiver_info');
parent::__construct('Plugin/Archiver', $namespaces, $module_handler, 'Drupal\Core\Archiver\Annotation\Archiver');
$this->alterInfo('archiver_info');
$this->setCacheBackend($cache_backend, $language_manager, 'archiver_info_plugins');
}
......
......@@ -33,10 +33,10 @@ class ConditionManager extends DefaultPluginManager implements ExecutableManager
* The module handler to invoke the alter hook with.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
$this->alterInfo($module_handler, 'condition_info');
$this->alterInfo('condition_info');
$this->setCacheBackend($cache_backend, $language_manager, 'condition_plugins');
parent::__construct('Plugin/Condition', $namespaces, 'Drupal\Core\Condition\Annotation\Condition');
parent::__construct('Plugin/Condition', $namespaces, $module_handler, 'Drupal\Core\Condition\Annotation\Condition');
}
/**
......
......@@ -41,8 +41,8 @@ class FieldTypePluginManager extends DefaultPluginManager implements FieldTypePl
* The module handler.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/Field/FieldType', $namespaces, 'Drupal\Core\Field\Annotation\FieldType');
$this->alterInfo($module_handler, 'field_info');
parent::__construct('Plugin/Field/FieldType', $namespaces, $module_handler, 'Drupal\Core\Field\Annotation\FieldType');
$this->alterInfo('field_info');
$this->setCacheBackend($cache_backend, $language_manager, 'field_types_plugins');
}
......
......@@ -49,10 +49,10 @@ class FormatterPluginManager extends DefaultPluginManager {
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LanguageManager $language_manager, FieldTypePluginManagerInterface $field_type_manager) {
parent::__construct('Plugin/Field/FieldFormatter', $namespaces, 'Drupal\Core\Field\Annotation\FieldFormatter');
parent::__construct('Plugin/Field/FieldFormatter', $namespaces, $module_handler, 'Drupal\Core\Field\Annotation\FieldFormatter');
$this->setCacheBackend($cache_backend, $language_manager, 'field_formatter_types_plugins');
$this->alterInfo($module_handler, 'field_formatter_info');
$this->alterInfo('field_formatter_info');
$this->fieldTypeManager = $field_type_manager;
}
......
......@@ -48,10 +48,10 @@ class WidgetPluginManager extends DefaultPluginManager {
* The 'field type' plugin manager.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LanguageManager $language_manager, FieldTypePluginManagerInterface $field_type_manager) {
parent::__construct('Plugin/Field/FieldWidget', $namespaces, 'Drupal\Core\Field\Annotation\FieldWidget');
parent::__construct('Plugin/Field/FieldWidget', $namespaces, $module_handler, 'Drupal\Core\Field\Annotation\FieldWidget');
$this->setCacheBackend($cache_backend, $language_manager, 'field_widget_types_plugins');
$this->alterInfo($module_handler, 'field_widget_info');
$this->alterInfo('field_widget_info');
$this->factory = new WidgetFactory($this);
$this->fieldTypeManager = $field_type_manager;
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Language\LanguageManager;
use Drupal\Core\Plugin\DefaultPluginManager;
......@@ -36,9 +37,11 @@ class ImageToolkitManager extends DefaultPluginManager {
* The language manager.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ConfigFactoryInterface $config_factory) {
parent::__construct('Plugin/ImageToolkit', $namespaces, 'Drupal\Core\ImageToolkit\Annotation\ImageToolkit');
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/ImageToolkit', $namespaces, $module_handler, 'Drupal\Core\ImageToolkit\Annotation\ImageToolkit');
$this->setCacheBackend($cache_backend, $language_manager, 'image_toolkit_plugins');
$this->configFactory = $config_factory;
......
......@@ -50,8 +50,8 @@ class MailManager extends DefaultPluginManager {
* The configuration factory.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory) {
parent::__construct('Plugin/Mail', $namespaces, 'Drupal\Core\Annotation\Mail');
$this->alterInfo($module_handler, 'mail_backend_info');
parent::__construct('Plugin/Mail', $namespaces, $module_handler, 'Drupal\Core\Annotation\Mail');
$this->alterInfo('mail_backend_info');
$this->setCacheBackend($cache_backend, $language_manager, 'mail_backend_plugins');
$this->mailConfig = $config_factory->get('system.mail');
}
......
......@@ -100,7 +100,8 @@ public function __construct(ControllerResolverInterface $controller_resolver, Mo
$this->controllerResolver = $controller_resolver;
$this->accessManager = $access_manager;
$this->account = $account;
$this->alterInfo($module_handler, 'contextual_links_plugins');
$this->moduleHandler = $module_handler;
$this->alterInfo('contextual_links_plugins');
$this->setCacheBackend($cache_backend, $language_manager, 'contextual_links_plugins');
}
......
......@@ -128,12 +128,12 @@ public function __construct(ControllerResolverInterface $controller_resolver, Re
$this->factory = new ContainerFactory($this);
$this->routeProvider = $route_provider;
$this->accessManager = $access_manager;
$this->moduleHandler = $module_handler;
$this->account = $account;
$this->controllerResolver = $controller_resolver;
$this->request = $request;
$this->alterInfo($module_handler, 'menu_local_actions');
$this->alterInfo('menu_local_actions');
$this->setCacheBackend($cache_backend, $language_manager, 'local_action_plugins', array('local_action' => TRUE));
}
/**
......
......@@ -137,7 +137,8 @@ public function __construct(ControllerResolverInterface $controller_resolver, Re
$this->routeBuilder = $route_builder;
$this->accessManager = $access_manager;
$this->account = $account;
$this->alterInfo($module_handler, 'local_tasks');
$this->moduleHandler = $module_handler;
$this->alterInfo('local_tasks');
$this->setCacheBackend($cache, $language_manager, 'local_task_plugins', array('local_task' => TRUE));
}
......
......@@ -106,15 +106,18 @@ class DefaultPluginManager extends PluginManagerBase implements PluginManagerInt
* @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\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param string $plugin_definition_annotation_name
* (optional) The name of the annotation that contains the plugin definition.
* Defaults to 'Drupal\Component\Annotation\Plugin'.
*/
public function __construct($subdir, \Traversable $namespaces, $plugin_definition_annotation_name = 'Drupal\Component\Annotation\Plugin') {
public function __construct($subdir, \Traversable $namespaces, ModuleHandlerInterface $module_handler, $plugin_definition_annotation_name = 'Drupal\Component\Annotation\Plugin') {
$this->subdir = $subdir;
$this->discovery = new AnnotatedClassDiscovery($subdir, $namespaces, $plugin_definition_annotation_name);
$this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery);
$this->factory = new ContainerFactory($this);
$this->moduleHandler = $module_handler;
}
/**
......@@ -150,13 +153,10 @@ public function setCacheBackend(CacheBackendInterface $cache_backend, LanguageMa
/**
* Initializes the alter hook.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler to invoke the alter hook with.
* @param string $alter_hook
* Name of the alter hook.
*/
protected function alterInfo(ModuleHandlerInterface $module_handler, $alter_hook) {
$this->moduleHandler = $module_handler;
protected function alterInfo($alter_hook) {
$this->alterHook = $alter_hook;
}
......@@ -267,6 +267,13 @@ protected function findDefinitions() {
if ($this->alterHook) {
$this->moduleHandler->alter($this->alterHook, $definitions);
}
// If this plugin was provided by a module that does not exist, remove the
// plugin definition.
foreach ($definitions as $plugin_id => $plugin_definition) {
if (isset($plugin_definition['provider']) && !in_array($plugin_definition['provider'], array('Core', 'Component')) && !$this->moduleHandler->moduleExists($plugin_definition['provider'])) {
unset($definitions[$plugin_id]);
}
}
return $definitions;
}
......
......@@ -45,11 +45,24 @@ class TypedDataManager extends DefaultPluginManager {
*/
protected $prototypes = array();
/**
* Constructs a new TypedDataManager.
*
* @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_backend
* Cache backend instance to use.
* @param \Drupal\Core\Language\LanguageManager $language_manager
* The language manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
$this->alterInfo($module_handler, 'data_type_info');
$this->alterInfo('data_type_info');
$this->setCacheBackend($cache_backend, $language_manager, 'typed_data_types_plugins');
parent::__construct('Plugin/DataType', $namespaces, 'Drupal\Core\TypedData\Annotation\DataType');
parent::__construct('Plugin/DataType', $namespaces, $module_handler, 'Drupal\Core\TypedData\Annotation\DataType');
}
/**
......
......@@ -47,9 +47,9 @@ class ConstraintManager extends DefaultPluginManager {
* The module handler to invoke the alter hook with.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/Validation/Constraint', $namespaces);
parent::__construct('Plugin/Validation/Constraint', $namespaces, $module_handler);
$this->discovery = new StaticDiscoveryDecorator($this->discovery, array($this, 'registerDefinitions'));
$this->alterInfo($module_handler, 'validation_constraint');
$this->alterInfo('validation_constraint');
$this->setCacheBackend($cache_backend, $language_manager, 'validation_constraint_plugins');
}
......
services:
plugin.manager.aggregator.fetcher:
class: Drupal\aggregator\Plugin\AggregatorPluginManager
arguments: [fetcher, '@container.namespaces', '@cache.cache', '@language_manager']
arguments: [fetcher, '@container.namespaces', '@cache.cache', '@language_manager', '@module_handler']
plugin.manager.aggregator.parser:
class: Drupal\aggregator\Plugin\AggregatorPluginManager
arguments: [parser, '@container.namespaces', '@cache.cache', '@language_manager']
arguments: [parser, '@container.namespaces', '@cache.cache', '@language_manager', '@module_handler']
plugin.manager.aggregator.processor:
class: Drupal\aggregator\Plugin\AggregatorPluginManager
arguments: [processor, '@container.namespaces', '@cache.cache', '@language_manager']
arguments: [processor, '@container.namespaces', '@cache.cache', '@language_manager', '@module_handler']
......@@ -8,6 +8,7 @@
namespace Drupal\aggregator\Plugin;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Language\LanguageManager;
use Drupal\Core\Plugin\DefaultPluginManager;
......@@ -28,15 +29,17 @@ class AggregatorPluginManager extends DefaultPluginManager {
* Cache backend instance to use.
* @param \Drupal\Core\Language\LanguageManager $language_manager
* The language manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager) {
public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
$type_annotations = array(
'fetcher' => 'Drupal\aggregator\Annotation\AggregatorFetcher',
'parser' => 'Drupal\aggregator\Annotation\AggregatorParser',
'processor' => 'Drupal\aggregator\Annotation\AggregatorProcessor',
);
parent::__construct("Plugin/aggregator/$type", $namespaces, $type_annotations[$type]);
parent::__construct("Plugin/aggregator/$type", $namespaces, $module_handler, $type_annotations[$type]);
$this->setCacheBackend($cache_backend, $language_manager, 'aggregator_' . $type . '_plugins');
}
......
......@@ -52,9 +52,9 @@ class BlockManager extends DefaultPluginManager {
* The translation manager.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler, TranslationInterface $translation_manager) {
parent::__construct('Plugin/Block', $namespaces, 'Drupal\block\Annotation\Block');
parent::__construct('Plugin/Block', $namespaces, $module_handler, 'Drupal\block\Annotation\Block');
$this->alterInfo($module_handler, 'block');
$this->alterInfo('block');
$this->setCacheBackend($cache_backend, $language_manager, 'block_plugins');
$this->translationManager = $translation_manager;
}
......
......@@ -33,8 +33,8 @@ class CKEditorPluginManager extends DefaultPluginManager {
* The module handler to invoke the alter hook with.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/CKEditorPlugin', $namespaces, 'Drupal\ckeditor\Annotation\CKEditorPlugin');
$this->alterInfo($module_handler, 'ckeditor_plugin_info');
parent::__construct('Plugin/CKEditorPlugin', $namespaces, $module_handler, 'Drupal\ckeditor\Annotation\CKEditorPlugin');
$this->alterInfo('ckeditor_plugin_info');
$this->setCacheBackend($cache_backend, $language_manager, 'ckeditor_plugins');
}
......
......@@ -34,6 +34,13 @@ class ConfigMapperManager extends DefaultPluginManager implements ConfigMapperMa
*/
protected $typedConfigManager;
/**
* The theme handler.
*
* @var \Drupal\Core\Extension\ThemeHandlerInterface
*/
protected $themeHandler;
/**
* {@inheritdoc}
*/
......@@ -77,7 +84,10 @@ public function __construct(CacheBackendInterface $cache_backend, LanguageManage
$this->factory = new ContainerFactory($this);
// Let others alter definitions with hook_config_translation_info_alter().
$this->alterInfo($module_handler, 'config_translation_info');
$this->moduleHandler = $module_handler;
$this->themeHandler = $theme_handler;
$this->alterInfo('config_translation_info');
$this->setCacheBackend($cache_backend, $language_manager, 'config_translation_info_plugins');
}
......@@ -104,6 +114,28 @@ public function processDefinition(&$definition, $plugin_id) {
}
}
/**
* {@inheritdoc}
*/
protected function findDefinitions() {
$definitions = $this->discovery->getDefinitions();
foreach ($definitions as $plugin_id => &$definition) {
$this->processDefinition($definition, $plugin_id);
}
if ($this->alterHook) {
$this->moduleHandler->alter($this->alterHook, $definitions);
}
// If this plugin was provided by a module that does not exist, remove the
// plugin definition.
foreach ($definitions as $plugin_id => $plugin_definition) {
if (isset($plugin_definition['provider']) && !in_array($plugin_definition['provider'], array('Core', 'Component')) && (!$this->moduleHandler->moduleExists($plugin_definition['provider']) && !in_array($plugin_definition['provider'], array_keys($this->themeHandler->listInfo())))) {
unset($definitions[$plugin_id]);
}
}
return $definitions;
}
/**
* {@inheritdoc}
*/
......
......@@ -31,8 +31,8 @@ class EditorManager extends DefaultPluginManager {
* The module handler to invoke the alter hook with.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/Editor', $namespaces, 'Drupal\editor\Annotation\Editor');
$this->alterInfo($module_handler, 'editor_info');
parent::__construct('Plugin/Editor', $namespaces, $module_handler, 'Drupal\editor\Annotation\Editor');
$this->alterInfo('editor_info');
$this->setCacheBackend($cache_backend, $language_manager, 'editor_plugins');
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment