1 color.module color_save_preview_settings($theme_name)

Callback function to handle saving preview settings to the user's session.

File

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

Code

function color_save_preview_settings($theme_name) {
  if (!isset($_GET['token']) || !backdrop_valid_token($_GET['token'], "color_token")) {
    return MENU_ACCESS_DENIED;
  }

  $themes = list_themes();
  if (in_array($theme_name, array_keys($themes))) {
    $theme_info = color_get_info($theme_name);

    // Check that the scheme is valid.
    if (isset($_POST['scheme'])
     && !empty($_POST['scheme'])
       && in_array($_POST['scheme'], array_keys($theme_info['schemes']))) {
      $scheme = $_POST['scheme'];
    }
    else {
      $scheme = '';
    }

    // Check that the palette is valid.
    if (isset($_POST['palette']) && is_array($_POST['palette'])) {
      $palette = $_POST['palette'];
      foreach ($palette as $field => $color) {
        if (!in_array($field, array_keys($theme_info['fields'])) || !color_valid_hexadecimal_string($color)) {
          unset($palette[$field]);
        }
      }
    }

    $_SESSION['color'][$theme_name] = array(
      'scheme' => $scheme,
      'palette' => $palette,
    );

    $data = array('success' => 1);
    backdrop_json_output($data);
  }
}