You are here

function less_wysiwyg_editor_settings_alter in Less CSS Preprocessor 8

Same name and namespace in other branches
  1. 7.4 includes/less.wysiwyg.inc \less_wysiwyg_editor_settings_alter()
  2. 7.2 less.wysiwyg.inc \less_wysiwyg_editor_settings_alter()
  3. 7.3 less.wysiwyg.inc \less_wysiwyg_editor_settings_alter()

Implements hook_wysiwyg_editor_settings_alter().

Check the CSS WYSIWYG setting for LESS files and replace with generated CSS files where necessary.

1 call to less_wysiwyg_editor_settings_alter()
less_ckeditor_settings_alter in includes/less.wysiwyg.inc
Implements hook_ckeditor_settings_alter().

File

includes/less.wysiwyg.inc, line 14
Contains functions that handle WYSIWYG module integration.

Code

function less_wysiwyg_editor_settings_alter(&$settings, $context) {
  $wysiwyg = $context['editor']['name'];

  // Each editor has a different $settings array key for CSS files.
  $editors = array(
    'tinymce' => 'content_css',
    'fckeditor' => 'EditorAreaCSS',
    'ckeditor' => 'contentsCss',
  );
  if (!empty($editors[$wysiwyg]) && !empty($settings[$editors[$wysiwyg]])) {
    $stylesheets = $settings[$editors[$wysiwyg]];

    // Keep track if comma separated paths, or array of paths.
    $is_array = is_array($stylesheets);
    if ($is_array === FALSE) {

      // $stylesheets is a list of comma separated file paths.
      $stylesheets = explode(',', $stylesheets);
    }

    // Prepare an array that can be handled by normal LESS module processing.
    $styles = array(
      '#items' => array(),
    );
    foreach ($stylesheets as $stylesheet) {

      // Might contain ?query portion, separate parts.
      $parts = drupal_parse_url($stylesheet);

      // Paths are expected to be relative to DRUPAL_ROOT, trim leading '/'.
      $path = trim($parts['path'], '/');
      $styles['#items'][$path] = array(
        'data' => $path,
      );
    }
    $styles = _less_pre_render($styles);
    $processed_stylesheets = array();
    foreach ($styles['#items'] as $file) {
      $processed_stylesheets[] = file_create_url($file['data']);
    }

    // Recombine file paths into comma separated list.
    if ($is_array === FALSE) {
      $processed_stylesheets = implode(',', $processed_stylesheets);
    }
    $settings[$editors[$wysiwyg]] = $processed_stylesheets;
  }
}