You are here

function blocks404_reset_body_classes in 404 Blocks 5

Resets the body classes if called from within a preprocess_page function.

1 call to blocks404_reset_body_classes()
_blocks404_preprocess_page in ./blocks404.active.inc
Helper function that performs the actual inclusion of the left and right regions.

File

./blocks404.active.inc, line 15

Code

function blocks404_reset_body_classes(&$vars) {

  // Determine the new layout variable.
  $layout = 'none';
  if (!empty($vars['left'])) {
    $layout = 'left';
  }
  if (!empty($vars['right'])) {
    $layout = $layout == 'left' ? 'both' : 'right';
  }

  // If the new layout is different than the old layout, reset the body classes.
  if ($layout != $vars['layout']) {

    // Some themes (like Zen) store body classes in an array.
    if (!empty($vars['body_classes_array'])) {
      $classes = $vars['body_classes_array'];
    }
    elseif (!empty($vars['classes_array'])) {
      $classes = $vars['classes_array'];
    }
    else {

      // Otherwise, we just act on core's $body_classes.
      $classes = explode(' ', $vars['body_classes']);
    }

    // Undo the old body classes. $pos will never be 0 because the first body
    // class is always front/not-front; see template_preprocess_page().
    if ($vars['layout'] == 'both' && ($pos = array_search('two-sidebars', $classes))) {
      unset($classes[$pos]);
    }
    else {
      if ($vars['layout'] == 'none' && ($pos = array_search('no-sidebars', $classes))) {
        unset($classes[$pos]);
      }
      else {
        if ($pos = array_search('one-sidebar', $classes)) {
          unset($classes[$pos]);
        }
        if ($pos = array_search('sidebar-' . $vars['layout'], $classes)) {
          unset($classes[$pos]);
        }
      }
    }

    // Save the new layout variable.
    $vars['layout'] = $layout;

    // Add information about the number of sidebars.
    if ($layout == 'both') {
      $classes[] = 'two-sidebars';
    }
    elseif ($layout == 'none') {
      $classes[] = 'no-sidebars';
    }
    else {
      $classes[] = 'one-sidebar';
      $classes[] = 'sidebar-' . $layout;
    }

    // Save the new body classes variables.
    if (!empty($vars['body_classes_array'])) {
      $vars['body_classes_array'] = $classes;
    }
    elseif (!empty($vars['classes_array'])) {
      $vars['classes_array'] = $classes;
    }
    $vars['body_classes'] = implode(' ', $classes);
  }
}