You are here

public function Editor::getAttachments in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/editor/src/Plugin/InPlaceEditor/Editor.php \Drupal\editor\Plugin\InPlaceEditor\Editor::getAttachments()

Returns the attachments for this editor.

Return value

array An array of attachments, for use with #attached.

Overrides InPlaceEditorInterface::getAttachments

See also

\Drupal\Core\Render\AttachmentsResponseProcessorInterface::processAttachments()

File

core/modules/editor/src/Plugin/InPlaceEditor/Editor.php, line 71
Contains \Drupal\editor\Plugin\InPlaceEditor\Editor.

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 = array();
  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;
}