You are here

public function Editor::getAttachments in Drupal 10

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;
}