Issue #2034563 by dawehner: Switch field plugin managers to DefaultPluginManager.

8.0.x
Alex Pott 2013-07-05 21:58:18 +01:00
parent a4c65bec40
commit 8c19f192d9
3 changed files with 38 additions and 16 deletions

View File

@ -1,10 +1,10 @@
services:
plugin.manager.field.widget:
class: Drupal\field\Plugin\Type\Widget\WidgetPluginManager
arguments: ['@container.namespaces']
arguments: ['@container.namespaces', '@cache.field', '@module_handler', '@language_manager']
plugin.manager.field.formatter:
class: Drupal\field\Plugin\Type\Formatter\FormatterPluginManager
arguments: ['@container.namespaces']
arguments: ['@container.namespaces', '@cache.field', '@module_handler', '@language_manager']
field.info:
class: Drupal\field\FieldInfo
arguments: ['@cache.field', '@config.factory', '@module_handler']

View File

@ -9,6 +9,10 @@ namespace Drupal\field\Plugin\Type\Formatter;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Language\LanguageManager;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Plugin\Discovery\CacheDecorator;
use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery;
use Drupal\Core\Plugin\Discovery\AlterDecorator;
@ -17,7 +21,7 @@ use Drupal\field\Plugin\Core\Entity\FieldInstance;
/**
* Plugin type manager for field formatters.
*/
class FormatterPluginManager extends PluginManagerBase {
class FormatterPluginManager extends DefaultPluginManager {
/**
* An array of formatter options for each field type.
@ -31,13 +35,21 @@ class FormatterPluginManager extends PluginManagerBase {
*
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
* keyed by the corresponding namespace to look for plugin implementations,
* 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\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Language\LanguageManager $language_manager
* The language manager.
*/
public function __construct(\Traversable $namespaces) {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LanguageManager $language_manager) {
$annotation_namespaces = array('Drupal\field\Annotation' => $namespaces['Drupal\field']);
$this->discovery = new AnnotatedClassDiscovery('field/formatter', $namespaces, $annotation_namespaces, 'Drupal\field\Annotation\FieldFormatter');
$this->discovery = new AlterDecorator($this->discovery, 'field_formatter_info');
$this->discovery = new CacheDecorator($this->discovery, 'field_formatter_types', 'field');
parent::__construct('field/formatter', $namespaces, $annotation_namespaces, 'Drupal\field\Annotation\FieldFormatter');
$this->setCacheBackend($cache_backend, $language_manager, 'field_formatter_types');
$this->alterInfo($module_handler, 'field_formatter_info');
}
/**

View File

@ -9,6 +9,10 @@ namespace Drupal\field\Plugin\Type\Widget;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Discovery\ProcessDecorator;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Language\LanguageManager;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Plugin\Discovery\CacheDecorator;
use Drupal\Core\Plugin\Discovery\AlterDecorator;
use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery;
@ -16,7 +20,7 @@ use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery;
/**
* Plugin type manager for field widgets.
*/
class WidgetPluginManager extends PluginManagerBase {
class WidgetPluginManager extends DefaultPluginManager {
/**
* An array of widget options for each field type.
@ -40,15 +44,21 @@ class WidgetPluginManager extends PluginManagerBase {
*
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
* keyed by the corresponding namespace to look for plugin implementations,
* 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\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Language\LanguageManager $language_manager
* The language manager.
*/
public function __construct(\Traversable $namespaces) {
$this->discovery = new AnnotatedClassDiscovery('field/widget', $namespaces);
$this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition'));
$this->discovery = new AlterDecorator($this->discovery, 'field_widget_info');
$this->discovery = new CacheDecorator($this->discovery, 'field_widget_types', 'field');
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LanguageManager $language_manager) {
parent::__construct('field/widget', $namespaces);
$this->factory = new WidgetFactory($this->discovery);
$this->setCacheBackend($cache_backend, $language_manager, 'field_widget_types');
$this->alterInfo($module_handler, 'field_widget_info');
$this->factory = new WidgetFactory($this);
}
/**