You are here

public function Core::alterEditorJS in BUEditor 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/BUEditorPlugin/Core.php \Drupal\bueditor\Plugin\BUEditorPlugin\Core::alterEditorJS()

Alters JS data of a BUEditor Editor.

Parameters

array $js: An associative array that holds 'libraries' and 'settings' of the editor.

\Drupal\bueditor\Entity\BUEditorEditor $bueditor_editor: BUEditor Editor entity that owns the data.

\Drupal\editor\Entity\Editor $editor: An optional Editor entity which the BUEditor Editor is attached to.

Overrides BUEditorPluginBase::alterEditorJS

File

src/Plugin/BUEditorPlugin/Core.php, line 52

Class

Core
Defines BUEditor Core plugin.

Namespace

Drupal\bueditor\Plugin\BUEditorPlugin

Code

public function alterEditorJS(array &$js, BUEditorEditor $bueditor_editor, Editor $editor = NULL) {

  // Add translation library for multilingual sites.
  $lang = \Drupal::service('language_manager')
    ->getCurrentLanguage()
    ->getId();
  if ($lang !== 'en' && \Drupal::service('module_handler')
    ->moduleExists('locale')) {
    $js['libraries'][] = 'bueditor/drupal.bueditor.translation';
  }

  // Add custom button definitions and libraries.
  $toolbar = BUEditorToolbarWrapper::set($js['settings']['toolbar']);
  if ($custom_items = $toolbar
    ->match('custom_')) {
    foreach (\Drupal::entityTypeManager()
      ->getStorage('bueditor_button')
      ->loadMultiple($custom_items) as $bid => $button) {
      $js['settings']['customButtons'][$bid] = $button
        ->jsProperties();
      foreach ($button
        ->get('libraries') as $library) {
        $js['libraries'][] = $library;
      }
    }
  }

  // Set editor id as the class name
  $cname =& $js['settings']['cname'];
  $cname = 'bue--' . $bueditor_editor
    ->id() . (isset($cname) ? ' ' . $cname : '');
}