You are here

public function AceEditor::getLibraries in Ace Code Editor 8

Returns libraries to be attached.

Because this is a method, plugins can dynamically choose to attach a different library for different configurations, instead of being forced to always use the same method.

Parameters

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

Return value

array An array of libraries that will be added to the page for use by this text editor.

Overrides EditorPluginInterface::getLibraries

See also

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

EditorManager::getAttachments()

File

src/Plugin/Editor/AceEditor.php, line 156

Class

AceEditor
Defines AceEditor as an Editor plugin.

Namespace

Drupal\ace_editor\Plugin\Editor

Code

public function getLibraries(Editor $editor) {

  // Get default ace_editor configuration.
  $config = \Drupal::config('ace_editor.settings');

  // Get theme and mode.
  $theme = trim($editor
    ->getSettings()['fieldset']['theme']);
  $mode = trim($editor
    ->getSettings()['fieldset']['syntax']);

  // Check if theme and mode library exist.
  $theme_exist = \Drupal::service('library.discovery')
    ->getLibraryByName('ace_editor', 'theme.' . $theme);
  $mode_exist = \Drupal::service('library.discovery')
    ->getLibraryByName('ace_editor', 'mode.' . $mode);

  // ace_editor/primary the basic library for ace_editor.
  $libs = [
    'ace_editor/primary',
  ];
  if ($theme_exist) {
    $libs[] = 'ace_editor/theme.' . $theme;
  }
  else {
    $libs[] = 'ace_editor/theme.' . $config
      ->get('theme');
  }
  if ($mode_exist) {
    $libs[] = 'ace_editor/mode.' . $mode;
  }
  else {
    $libs[] = 'ace_editor/mode.' . $config
      ->get('syntax');
  }
  return $libs;
}