Commit 8e47a4eb authored by alexpott's avatar alexpott

Issue #2204621 by Berdir: Convert InPlaceEditorManager to DefaultPluginManager.

parent a02ae4a1
services:
plugin.manager.edit.editor:
class: Drupal\edit\Plugin\InPlaceEditorManager
arguments: ['@container.namespaces']
parent: default_plugin_manager
access_check.edit.entity_field:
class: Drupal\edit\Access\EditEntityFieldAccessCheck
arguments: ['@entity.manager']
......
......@@ -7,32 +7,35 @@
namespace Drupal\edit\Plugin;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Discovery\ProcessDecorator;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\Core\Plugin\Discovery\AlterDecorator;
use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery;
use Drupal\Core\Plugin\Discovery\CacheDecorator;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
/**
* Editor manager.
*
* The form editor must always be available.
*/
class InPlaceEditorManager extends PluginManagerBase {
class InPlaceEditorManager extends DefaultPluginManager {
/**
* Overrides \Drupal\Component\Plugin\PluginManagerBase::__construct().
* Constructs a InPlaceEditorManager object.
*
* @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\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler to invoke the alter hook with.
*/
public function __construct(\Traversable $namespaces) {
$this->discovery = new AnnotatedClassDiscovery('Plugin/InPlaceEditor', $namespaces, 'Drupal\edit\Annotation\InPlaceEditor');
$this->discovery = new AlterDecorator($this->discovery, 'edit_editor');
$this->discovery = new CacheDecorator($this->discovery, 'edit:editor');
$this->factory = new DefaultFactory($this->discovery);
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/InPlaceEditor', $namespaces, $module_handler, 'Drupal\edit\Annotation\InPlaceEditor');
$this->alterInfo('edit_editor');
$this->setCacheBackend($cache_backend, $language_manager, 'edit:editor');
}
}
......@@ -134,6 +134,10 @@ public function testEditorWithCustomMetadata() {
// Enable edit_test module so that the WYSIWYG editor becomes available.
$this->enableModules(array('edit_test'));
$this->editorManager = $this->container->get('plugin.manager.edit.editor');
$this->editorSelector = new EditorSelector($this->editorManager, $this->container->get('plugin.manager.field.formatter'));
$this->metadataGenerator = new MetadataGenerator($this->accessChecker, $this->editorSelector, $this->editorManager);
// Create a rich text field.
$field_name = 'field_rich';
$field_label = 'Rich text field';
......
......@@ -124,8 +124,8 @@ protected function getSelectedEditor($entity_id, $field_name, $view_mode = 'defa
* format compatibility.
*/
public function testEditorSelection() {
$this->editorManager = new InPlaceEditorManager($this->container->get('container.namespaces'));
$this->editorSelector = new EditorSelector($this->editorManager, $this->container->get('plugin.manager.field.formatter'));
$this->editorManager = $this->container->get('plugin.manager.edit.editor');
$this->editorSelector = $this->container->get('edit.editor.selector');
// Create an entity with values for this text field.
$this->entity = entity_create('entity_test');
......@@ -151,9 +151,9 @@ public function testEditorSelection() {
* Tests (custom) metadata when the formatted text editor is used.
*/
public function testMetadata() {
$this->editorManager = new InPlaceEditorManager($this->container->get('container.namespaces'));
$this->editorManager = $this->container->get('plugin.manager.edit.editor');
$this->accessChecker = new MockEditEntityFieldAccessCheck();
$this->editorSelector = new EditorSelector($this->editorManager, $this->container->get('plugin.manager.field.formatter'));
$this->editorSelector = $this->container->get('edit.editor.selector');
$this->metadataGenerator = new MetadataGenerator($this->accessChecker, $this->editorSelector, $this->editorManager);
// Create an entity with values for the field.
......
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