function Editor::getAttachments

Same name in this branch
  1. 9 core/modules/editor/src/Plugin/InPlaceEditor/Editor.php \Drupal\editor\Plugin\InPlaceEditor\Editor::getAttachments()
Same name in other branches
  1. 8.9.x core/modules/editor/src/Plugin/InPlaceEditor/Editor.php \Drupal\editor\Plugin\InPlaceEditor\Editor::getAttachments()

Overrides InPlaceEditorInterface::getAttachments

File

core/modules/quickedit/src/Plugin/InPlaceEditor/Editor.php, line 70

Class

Editor
Defines the formatted text in-place editor.

Namespace

Drupal\quickedit\Plugin\InPlaceEditor

Code

public function getAttachments() {
    $user = \Drupal::currentUser();
    $user_format_ids = array_keys(filter_formats($user));
    $manager = \Drupal::service('plugin.manager.editor');
    $definitions = $manager->getDefinitions();
    // Filter the current user's formats to those that support inline editing.
    $formats = [];
    foreach ($user_format_ids as $format_id) {
        if ($editor = editor_load($format_id)) {
            $editor_id = $editor->getEditor();
            if (isset($definitions[$editor_id]['supports_inline_editing']) && $definitions[$editor_id]['supports_inline_editing'] === TRUE) {
                $formats[] = $format_id;
            }
        }
    }
    // Get the attachments for all text editors that the user might use.
    $attachments = $manager->getAttachments($formats);
    // Also include quickedit.module's formatted text editor.
    $attachments['library'][] = 'quickedit/quickedit.inPlaceEditor.formattedText';
    return $attachments;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.