You are here

bueditor.module in BUEditor 8

Defines Drupal hooks for BUEditor.

File

bueditor.module
View source
<?php

/**
 * @file
 * Defines Drupal hooks for BUEditor.
 */
use Drupal\Core\Url;

/**
 * Implements hook_js_settings_alter().
 */
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();
  }
}

/**
 * Implements hook_library_info_alter().
 */
function bueditor_library_info_alter(array &$libraries, $module) {

  // Use dev version of BUE library if dev mode is on.
  if ($module === 'bueditor' && \Drupal::config('bueditor.settings')
    ->get('devmode')) {
    $libraries['BUE'] = $libraries['BUE.dev'];
  }
}