You are here

public function CKEditor::getJSSettings in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/ckeditor/src/Plugin/Editor/CKEditor.php \Drupal\ckeditor\Plugin\Editor\CKEditor::getJSSettings()

Returns JavaScript settings to be attached.

Most text editors use JavaScript to provide a WYSIWYG or toolbar on the client-side interface. This method can be used to convert internal settings of the text editor into JavaScript variables that will be accessible when the text editor is loaded.

Parameters

\Drupal\editor\Entity\Editor $editor: A configured text editor object.

Return value

array An array of settings that will be added to the page for use by this text editor's JavaScript integration.

Overrides EditorPluginInterface::getJSSettings

See also

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

EditorManager::getAttachments()

1 call to CKEditor::getJSSettings()
CKEditor::settingsForm in core/modules/ckeditor/src/Plugin/Editor/CKEditor.php
Returns a settings form to configure this text editor.

File

core/modules/ckeditor/src/Plugin/Editor/CKEditor.php, line 262
Contains \Drupal\ckeditor\Plugin\Editor\CKEditor.

Class

CKEditor
Defines a CKEditor-based text editor for Drupal.

Namespace

Drupal\ckeditor\Plugin\Editor

Code

public function getJSSettings(EditorEntity $editor) {
  $settings = array();

  // Get the settings for all enabled plugins, even the internal ones.
  $enabled_plugins = array_keys($this->ckeditorPluginManager
    ->getEnabledPluginFiles($editor, TRUE));
  foreach ($enabled_plugins as $plugin_id) {
    $plugin = $this->ckeditorPluginManager
      ->createInstance($plugin_id);
    $settings += $plugin
      ->getConfig($editor);
  }

  // Fall back on English if no matching language code was found.
  $display_langcode = 'en';

  // Map the interface language code to a CKEditor translation if interface
  // translation is enabled.
  if ($this->moduleHandler
    ->moduleExists('locale')) {
    $ckeditor_langcodes = $this
      ->getLangcodes();
    $language_interface = $this->languageManager
      ->getCurrentLanguage();
    if (isset($ckeditor_langcodes[$language_interface
      ->getId()])) {
      $display_langcode = $ckeditor_langcodes[$language_interface
        ->getId()];
    }
  }

  // Next, set the most fundamental CKEditor settings.
  $external_plugin_files = $this->ckeditorPluginManager
    ->getEnabledPluginFiles($editor);
  $settings += array(
    'toolbar' => $this
      ->buildToolbarJSSetting($editor),
    'contentsCss' => $this
      ->buildContentsCssJSSetting($editor),
    'extraPlugins' => implode(',', array_keys($external_plugin_files)),
    'language' => $display_langcode,
    // Configure CKEditor to not load styles.js. The StylesCombo plugin will
    // set stylesSet according to the user's settings, if the "Styles" button
    // is enabled. We cannot get rid of this until CKEditor will stop loading
    // styles.js by default.
    // See http://dev.ckeditor.com/ticket/9992#comment:9.
    'stylesSet' => FALSE,
  );

  // Finally, set Drupal-specific CKEditor settings.
  $settings += array(
    'drupalExternalPlugins' => array_map('file_create_url', $external_plugin_files),
  );

  // Parse all CKEditor plugin JavaScript files for translations.
  if ($this->moduleHandler
    ->moduleExists('locale')) {
    locale_js_translate(array_values($external_plugin_files));
  }
  ksort($settings);
  return $settings;
}