function Editor::getAttachments

Same name in other branches
  1. 9 core/modules/quickedit/src/Plugin/InPlaceEditor/Editor.php \Drupal\quickedit\Plugin\InPlaceEditor\Editor::getAttachments()
  2. 9 core/modules/editor/src/Plugin/InPlaceEditor/Editor.php \Drupal\editor\Plugin\InPlaceEditor\Editor::getAttachments()

Overrides InPlaceEditorInterface::getAttachments

File

core/modules/editor/src/Plugin/InPlaceEditor/Editor.php, line 69

Class

Editor
Defines the formatted text in-place editor.

Namespace

Drupal\editor\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 editor.module's formatted text editor.
    $attachments['library'][] = 'editor/quickedit.inPlaceEditor.formattedText';
    return $attachments;
}

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