You are here

public function XPreview::alterEditorJS in BUEditor 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/BUEditorPlugin/XPreview.php \Drupal\bueditor\Plugin\BUEditorPlugin\XPreview::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/XPreview.php, line 34

Class

XPreview
Defines BUEditor Ajax Preview plugin.

Namespace

Drupal\bueditor\Plugin\BUEditorPlugin

Code

public function alterEditorJS(array &$js, BUEditorEditor $bueditor_editor, Editor $editor = NULL) {
  $toolbar = BUEditorToolbarWrapper::set($js['settings']['toolbar']);

  // Check ajax preview button.
  if ($toolbar
    ->has('xpreview')) {

    // Check access and add the library
    if (\Drupal::currentUser()
      ->hasPermission('access ajax preview')) {
      $js['libraries'][] = 'bueditor/drupal.bueditor.xpreview';
    }
    else {
      $toolbar
        ->remove('xpreview');
    }
  }
}