You are here

function bueditor_js_settings_alter in BUEditor 8

Same name and namespace in other branches
  1. 8.2 bueditor.module \bueditor_js_settings_alter()

Implements hook_js_settings_alter().

File

./bueditor.module, line 13
Defines Drupal hooks for BUEditor.

Code

function bueditor_js_settings_alter(array &$settings, \Drupal\Core\Asset\AttachedAssetsInterface $assets) {

  // XPreview library requires a tokenized URL.
  $libraries = \Drupal::service('library.dependency_resolver')
    ->getLibrariesWithDependencies($assets
    ->getLibraries());
  if (in_array('bueditor/drupal.xpreview', $libraries)) {
    $options = [];
    if (!\Drupal::currentUser()
      ->isAnonymous()) {
      $options['query']['token'] = \Drupal::csrfToken()
        ->get('xpreview');
    }
    $settings['xPreview']['url'] = Url::fromRoute('drupal.xpreview', [], $options)
      ->toString();
  }
}