diff --git a/core/modules/editor/editor.module b/core/modules/editor/editor.module index e37683fa0ac..d6fa16c5c00 100644 --- a/core/modules/editor/editor.module +++ b/core/modules/editor/editor.module @@ -67,6 +67,20 @@ function editor_element_info_alter(&$types) { /** * Implements hook_form_FORM_ID_alter() for \Drupal\filter\FilterFormatListBuilder. + * + * Implements hook_field_formatter_info_alter(). + * + * @see quickedit_field_formatter_info_alter() + */ +function editor_field_formatter_info_alter(&$info) { + // Update \Drupal\text\Plugin\Field\FieldFormatter\TextDefaultFormatter's + // annotation to indicate that it supports the 'editor' in-place editor + // provided by this module. + $info['text_default']['quickedit'] = ['editor' => 'editor']; +} + +/** + * Implements hook_form_FORM_ID_alter(). */ function editor_form_filter_admin_overview_alter(&$form, FormStateInterface $form_state) { // @todo Cleanup column injection: https://www.drupal.org/node/1876718. diff --git a/core/modules/editor/src/Plugin/InPlaceEditor/Editor.php b/core/modules/editor/src/Plugin/InPlaceEditor/Editor.php index 56158f539b3..5d5034293a0 100644 --- a/core/modules/editor/src/Plugin/InPlaceEditor/Editor.php +++ b/core/modules/editor/src/Plugin/InPlaceEditor/Editor.php @@ -12,8 +12,7 @@ use Drupal\filter\Plugin\FilterInterface; * Defines the formatted text in-place editor. * * @InPlaceEditor( - * id = "editor", - * alternativeTo = {"plain_text"} + * id = "editor" * ) */ class Editor extends PluginBase implements InPlaceEditorInterface { @@ -31,16 +30,14 @@ class Editor extends PluginBase implements InPlaceEditorInterface { // This editor is compatible with formatted ("rich") text fields; but only // if there is a currently active text format, that text format has an // associated editor and that editor supports inline editing. - elseif (in_array($field_definition->getType(), array('text', 'text_long', 'text_with_summary'), TRUE)) { - if ($editor = editor_load($items[0]->format)) { - $definition = \Drupal::service('plugin.manager.editor')->getDefinition($editor->getEditor()); - if ($definition['supports_inline_editing'] === TRUE) { - return TRUE; - } + elseif ($editor = editor_load($items[0]->format)) { + $definition = \Drupal::service('plugin.manager.editor')->getDefinition($editor->getEditor()); + if ($definition['supports_inline_editing'] === TRUE) { + return TRUE; } - - return FALSE; } + + return FALSE; } /** diff --git a/core/modules/quickedit/src/Annotation/InPlaceEditor.php b/core/modules/quickedit/src/Annotation/InPlaceEditor.php index f30d8e03abc..8c9594b5e91 100644 --- a/core/modules/quickedit/src/Annotation/InPlaceEditor.php +++ b/core/modules/quickedit/src/Annotation/InPlaceEditor.php @@ -27,14 +27,6 @@ class InPlaceEditor extends Plugin { */ public $id; - /** - * An array of in-place editors plugin IDs that have registered themselves as - * alternatives to this in-place editor. - * - * @var array - */ - public $alternativeTo; - /** * The name of the module providing the in-place editor plugin. * diff --git a/core/modules/quickedit/src/EditorSelector.php b/core/modules/quickedit/src/EditorSelector.php index 6b199fa2bd6..9e2252e6cca 100644 --- a/core/modules/quickedit/src/EditorSelector.php +++ b/core/modules/quickedit/src/EditorSelector.php @@ -50,21 +50,8 @@ class EditorSelector implements EditorSelectorInterface { * {@inheritdoc} */ public function getEditor($formatter_type, FieldItemListInterface $items) { - // Build a static cache of the editors that have registered themselves as - // alternatives to a certain editor. - if (!isset($this->alternatives)) { - $editors = $this->editorManager->getDefinitions(); - foreach ($editors as $alternative_editor_id => $editor) { - if (isset($editor['alternativeTo'])) { - foreach ($editor['alternativeTo'] as $original_editor_id) { - $this->alternatives[$original_editor_id][] = $alternative_editor_id; - } - } - } - } - // Check if the formatter defines an appropriate in-place editor. For - // example, text formatters displaying untrimmed text can choose to use the + // example, text formatters displaying plain text can choose to use the // 'plain_text' editor. If the formatter doesn't specify, fall back to the // 'form' editor, since that can work for any field. Formatter definitions // can use 'disabled' to explicitly opt out of in-place editing. diff --git a/core/modules/quickedit/src/Plugin/InPlaceEditor/PlainTextEditor.php b/core/modules/quickedit/src/Plugin/InPlaceEditor/PlainTextEditor.php index 08f4efa54a0..1f61a5621cc 100644 --- a/core/modules/quickedit/src/Plugin/InPlaceEditor/PlainTextEditor.php +++ b/core/modules/quickedit/src/Plugin/InPlaceEditor/PlainTextEditor.php @@ -21,16 +21,7 @@ class PlainTextEditor extends InPlaceEditorBase { $field_definition = $items->getFieldDefinition(); // This editor is incompatible with multivalued fields. - if ($field_definition->getFieldStorageDefinition()->getCardinality() != 1) { - return FALSE; - } - // This editor is incompatible with formatted ("rich") text fields. - elseif (in_array($field_definition->getType(), array('text', 'text_long', 'text_with_summary'), TRUE)) { - return FALSE; - } - else { - return TRUE; - } + return $field_definition->getFieldStorageDefinition()->getCardinality() == 1; } /** diff --git a/core/modules/quickedit/tests/modules/quickedit_test.module b/core/modules/quickedit/tests/modules/quickedit_test.module index cd12fc9727f..3d2106d31ea 100644 --- a/core/modules/quickedit/tests/modules/quickedit_test.module +++ b/core/modules/quickedit/tests/modules/quickedit_test.module @@ -18,3 +18,16 @@ function quickedit_test_quickedit_render_field(EntityInterface $entity, $field_n '#suffix' => '', ); } + +/** + * Implements hook_field_formatter_info_alter(). + * + * @see quickedit_field_formatter_info_alter() + * @see editor_field_formatter_info_alter() + */ +function quickedit_test_field_formatter_info_alter(&$info) { + // Update \Drupal\text\Plugin\Field\FieldFormatter\TextDefaultFormatter's + // annotation to indicate that it supports the 'wysiwyg' in-place editor + // provided by this module. + $info['text_default']['quickedit'] = ['editor' => 'wysiwyg']; +} diff --git a/core/modules/quickedit/tests/modules/src/Plugin/InPlaceEditor/WysiwygEditor.php b/core/modules/quickedit/tests/modules/src/Plugin/InPlaceEditor/WysiwygEditor.php index 8ce768f625b..596df75a5c2 100644 --- a/core/modules/quickedit/tests/modules/src/Plugin/InPlaceEditor/WysiwygEditor.php +++ b/core/modules/quickedit/tests/modules/src/Plugin/InPlaceEditor/WysiwygEditor.php @@ -10,7 +10,6 @@ use Drupal\quickedit\Plugin\InPlaceEditorBase; * * @InPlaceEditor( * id = "wysiwyg", - * alternativeTo = {"plain_text"} * ) */ class WysiwygEditor extends InPlaceEditorBase { @@ -28,12 +27,7 @@ class WysiwygEditor extends InPlaceEditorBase { // This editor is compatible with formatted ("rich") text fields; but only // if there is a currently active text format and that text format is the // 'full_html' text format. - elseif (in_array($field_definition->getType(), array('text', 'text_long', 'text_with_summary'), TRUE)) { - if ($items[0]->format === 'full_html') { - return TRUE; - } - return FALSE; - } + return $items[0]->format === 'full_html'; } /** diff --git a/core/modules/text/src/Plugin/Field/FieldFormatter/TextDefaultFormatter.php b/core/modules/text/src/Plugin/Field/FieldFormatter/TextDefaultFormatter.php index c57a6a8e5e1..0a78114185f 100644 --- a/core/modules/text/src/Plugin/Field/FieldFormatter/TextDefaultFormatter.php +++ b/core/modules/text/src/Plugin/Field/FieldFormatter/TextDefaultFormatter.php @@ -15,9 +15,6 @@ use Drupal\Core\Field\FieldItemListInterface; * "text", * "text_long", * "text_with_summary", - * }, - * quickedit = { - * "editor" = "plain_text" * } * ) */