You are here

public function EditorManager::getAttachments in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/editor/src/Plugin/EditorManager.php \Drupal\editor\Plugin\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\Core\Render\AttachmentsResponseProcessorInterface::processAttachments()

File

core/modules/editor/src/Plugin/EditorManager.php, line 66
Contains \Drupal\editor\Plugin\EditorManager.

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
      ->getEditor());
    $plugin_definition = $plugin
      ->getPluginDefinition();

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

    // Format-specific JavaScript settings.
    $settings['editor']['formats'][$format_id] = array(
      'format' => $format_id,
      'editor' => $editor
        ->getEditor(),
      'editorSettings' => $plugin
        ->getJSSettings($editor),
      'editorSupportsContentFiltering' => $plugin_definition['supports_content_filtering'],
      'isXssSafe' => $plugin_definition['is_xss_safe'],
    );
  }

  // Allow other modules to alter all JavaScript settings.
  $this->moduleHandler
    ->alter('editor_js_settings', $settings);
  if (empty($attachments['library']) && empty($settings)) {
    return array();
  }
  $attachments['drupalSettings'] = $settings;
  return $attachments;
}