function template_preprocess_color_scheme_form

Prepares variables for color scheme form templates.

Default template: color-scheme-form.html.twig.

Parameters

array $variables: An associative array containing:

  • form: A render element representing the form.

File

drupal/core/modules/color/color.module, line 245
Allows users to change the color scheme of themes.

Code

function template_preprocess_color_scheme_form(&$variables) {
  $form = $variables['form'];
  $theme = $form['theme']['#value'];
  $info = $form['info']['#value'];
  $path = drupal_get_path('theme', $theme) . '/';
  drupal_add_css($path . $info['preview_css']);

  // @todo Transform to add library.
  $preview_js_path = isset($info['preview_js']) ? $path . $info['preview_js'] : drupal_get_path('module', 'color') . '/' . 'preview.js';

  // Add the JS at a weight below color.js.
  drupal_add_js($preview_js_path, array(
    'weight' => -1,
  ));

  // Attempt to load preview HTML if the theme provides it.
  $preview_html_path = DRUPAL_ROOT . '/' . (isset($info['preview_html']) ? drupal_get_path('theme', $theme) . '/' . $info['preview_html'] : drupal_get_path('module', 'color') . '/preview.html');
  $variables['html_preview'] = file_get_contents($preview_html_path);
}