Issue #2327941 by Wim Leers, Sonal.Sangale: Simplify in-place editor selection (Was: Refactor PlainTextEditor/WysiwygEditor/Editor in-place editors now that text fields no longer have configurable filteredness)
parent
b313cdcd8b
commit
bc084e183c
|
@ -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.
|
||||
|
|
|
@ -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,8 +30,7 @@ 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)) {
|
||||
elseif ($editor = editor_load($items[0]->format)) {
|
||||
$definition = \Drupal::service('plugin.manager.editor')->getDefinition($editor->getEditor());
|
||||
if ($definition['supports_inline_editing'] === TRUE) {
|
||||
return TRUE;
|
||||
|
@ -41,7 +39,6 @@ class Editor extends PluginBase implements InPlaceEditorInterface {
|
|||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,3 +18,16 @@ function quickedit_test_quickedit_render_field(EntityInterface $entity, $field_n
|
|||
'#suffix' => '</div>',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'];
|
||||
}
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,9 +15,6 @@ use Drupal\Core\Field\FieldItemListInterface;
|
|||
* "text",
|
||||
* "text_long",
|
||||
* "text_with_summary",
|
||||
* },
|
||||
* quickedit = {
|
||||
* "editor" = "plain_text"
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue