You are here

function styleswitcher_update_7201 in Style Switcher 7.2

Ensure default (blank) style is in place.

File

./styleswitcher.install, line 31
Installation tasks.

Code

function styleswitcher_update_7201() {
  $styles = variable_get('styleswitcher_styles');
  if (isset($styles)) {
    $blank_is_in_place = FALSE;
    $blank_css_path = drupal_get_path('module', 'styleswitcher') . '/styleswitcher.css';
    $min_weight = 0;
    foreach ($styles as $name => $style) {
      if ($style['path'] == $blank_css_path) {

        // No need to add anything.
        $blank_is_in_place = TRUE;
        break;
      }
      $min_weight = min($min_weight, $style['weight']);
    }
    if (!$blank_is_in_place) {
      $name = 'default';
      if (isset($styles[$name])) {
        $i = 0;
        do {
          ++$i;
          $name = 'default_' . $i;
        } while (isset($styles[$name]));
      }
      $styles[$name] = array(
        'name' => $name,
        'label' => 'Default',
        'path' => $blank_css_path,
        'weight' => $min_weight - 1,
        'custom' => TRUE,
        // Add it disabled to not mess established things.
        'status' => FALSE,
        'is_default' => FALSE,
      );
      if (count($styles) > 1) {
        uasort($styles, 'drupal_sort_weight');
      }
      variable_set('styleswitcher_styles', $styles);
      return 'Style Switcher module has been updated. You might want to ' . l('configure it', 'admin/config/user-interface/styleswitcher') . '.';
    }
  }
}