You are here

function om_node_preprocess_page in OM Tools 6.2

Same name and namespace in other branches
  1. 8 tools/node/node.inc \om_node_preprocess_page()
  2. 6 tools/node/node.inc \om_node_preprocess_page()
  3. 7 tools/node/node.inc \om_node_preprocess_page()

Override or insert om variables into the templates.

File

tools/node/node.inc, line 63
Node Tools

Code

function om_node_preprocess_page(&$vars) {
  $node_tools = $vars['om_node_tools_values'];
  if (isset($node_tools['node_body_classes_switch']) && $node_tools['node_body_classes_switch'] == 1 || isset($node_tools['node_terms_classes_switch']) && $node_tools['node_terms_classes_switch'] == 1 || isset($node_tools['node_type_titles_switch']) && $node_tools['node_type_titles_switch'] == 1) {
    $classes = explode(' ', $vars['body_classes']);
    if (!$vars['is_front']) {

      // Add unique class for each page.
      $path = drupal_get_path_alias($_GET['q']);

      // path title
      $classes[] = om_tools_class_safe('page-' . $path);

      // default section
      list($section) = explode('/', $path, 2);
      $arg = arg();

      // get all arguments
      if ($arg[0] == 'node') {
        $node_type = isset($vars['node']->type) ? $vars['node']->type : '';
        if (isset($node_tools['node_body_classes']) && $node_tools['node_body_classes'] == 1) {
          if ($arg[1] == 'add' && isset($arg[2])) {

            // add node
            $section = 'node-add';
            $page_type = $arg[2];
            $page_type_op = $page_type . '-add';
          }
          elseif ($arg[1] == 'add' && !isset($arg[2])) {

            // add any node
            $section = 'node-add';
            $page_type = 'any';
            $page_type_op = $page_type . '-add';
          }
          elseif (is_numeric($arg[1]) && !isset($arg[2]) && empty($node_type)) {

            // not found
            $section = 'page-not-found';
            $page_type = 'any';
            $page_type_op = $page_type . '-view';
          }
          elseif (is_numeric($arg[1]) && !isset($arg[2])) {

            // view node
            // default $section
            $page_type = $node_type;
            $page_type_op = $page_type . '-view';
          }
          elseif (is_numeric($arg[1]) && isset($arg[2])) {

            // has arg 2, like delete, edit, etc.
            $section = 'node-' . $arg[2];
            $page_type = !empty($node_type) ? $node_type : 'any';
            $page_type_op = $page_type . '-' . $arg[2];
          }
          $classes[] = om_tools_class_safe($node_tools['node_body_classes_prefix'] . $page_type);
          $classes[] = om_tools_class_safe($node_tools['node_body_classes_prefix'] . $page_type_op);
        }

        // node terms
        if (isset($node_tools['node_terms_classes_switch']) && $node_tools['node_terms_classes_switch'] == 1) {

          // Term classes
          if (!empty($vars['node']->taxonomy) && $node_tools['node_terms_classes']) {
            foreach ($vars['node']->taxonomy as $term) {
              $classes[] = om_tools_class_safe($node_tools['node_terms_classes_prefix'] . $term->name);
            }
          }
        }

        // node titles
        if (isset($node_tools['node_type_titles_switch']) && $node_tools['node_type_titles_switch'] == 1) {
          if (!empty($node_type) && !empty($node_tools['node_' . $node_type . '_titles'])) {
            unset($vars['title']);
            $classes[] = 'om-tools-no-title';
          }
        }
      }
      $classes[] = om_tools_class_safe('section-' . $section);
      $classes[] = 'om-tools-active';
    }
    $vars['body_classes_array'] = $classes;
    $vars['body_classes'] = implode(' ', $classes);

    // Concatenate with spaces.

    //dsm($vars);
  }
}