public function EditorManager::getAttachments

Retrieves text editor libraries and JavaScript settings.

Parameters

array $format_ids: An array of format IDs as returned by array_keys(filter_formats()).

Return value

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

See also

drupal_process_attached()

File

drupal/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php, line 62
Contains \Drupal\editor\Plugin\InPlaceEditorManager.

Class

EditorManager
Configurable text editor manager.

Namespace

Drupal\editor\Plugin

Code

public function getAttachments(array $format_ids) {
  $attachments = array(
    'library' => array(),
  );
  $settings = array();
  foreach ($format_ids as $format_id) {
    $editor = editor_load($format_id);
    if (!$editor) {
      continue;
    }
    $plugin = $this
      ->createInstance($editor->editor);

    // Libraries.
    $attachments['library'] = array_merge($attachments['library'], $plugin
      ->getLibraries($editor));

    // JavaScript settings.
    $settings[$format_id] = array(
      'editor' => $editor->editor,
      'editorSettings' => $plugin
        ->getJSSettings($editor),
    );
  }

  // We have all JavaScript settings, allow other modules to alter them.
  drupal_alter('editor_js_settings', $settings);
  if (empty($attachments['library']) && empty($settings)) {
    return array();
  }
  $attachments['js'][] = array(
    'type' => 'setting',
    'data' => array(
      'editor' => array(
        'formats' => $settings,
      ),
    ),
  );
  return $attachments;
}