You are here

function _nd_preprocess_node in Node displays 6

Same name and namespace in other branches
  1. 6.3 nd.module \_nd_preprocess_node()
  2. 6.2 nd.module \_nd_preprocess_node()
  3. 7 nd.module \_nd_preprocess_node()

Helper function used in either nd_preprocess_node or other preprocess function.

1 call to _nd_preprocess_node()
nd_preprocess_node in ./nd.module
Implementation of moduleName_preprocess_hook(). The node data will be rendered in regions. This uses a helper function so themers/developers can call that helper function from within their preprocess_hooks if they are fiddling with some data. For…

File

./nd.module, line 195
Main node displays file.

Code

function _nd_preprocess_node(&$vars, $hook) {
  $node = $vars['node'];

  // Add node-content_type-build_mode(-nid) template suggestion.
  $vars['template_files'][] = 'node-' . $node->type . '-' . $node->build_mode;
  $vars['template_files'][] = 'node-' . $node->type . '-' . $node->build_mode . '-' . $node->nid;

  // Break all the rendering if needed. The render_by_nd key is set in nodeapi above.
  if (!$node->render_by_nd) {
    return;
  }
  $all_regions = nd_regions('anything', TRUE);
  $regions = $vars['regions'];
  $themed_regions = array();
  $nd_display_settings = variable_get('nd_display_settings_' . $node->type, array());

  // Create key_rendered fields from ND_FIELD_PREPROCESS types.
  $fields = nd_get_fields($node->type, $node->has_body, $node->build_mode);
  if (!empty($fields)) {
    foreach ($fields as $key => $field) {
      if ($field['type'] == ND_FIELD_PREPROCESS && isset($node->nd_fields[$key])) {
        $field_key = $key . '_rendered';
        $vars[$field_key] = $vars[$key];
        unset($vars[$key]);
      }
      if ($field['type'] == ND_FIELD_IGNORE) {
        $field_key = $key . '_rendered';
        $vars[$field_key] = $node->content[$key]['#value'];
      }
    }
  }

  // Loop through all regions and content and classes.
  $region_classes = array();
  foreach ($all_regions as $region_name => $region_title) {
    if (isset($regions[$region_name])) {
      $region_content = '';
      $region = $regions[$region_name];

      // Loop through all fields after ordering on weight.
      asort($region);
      foreach ($region as $key => $weight) {
        $field_content = isset($vars[$key . '_rendered']) ? $vars[$key . '_rendered'] : '';
        if (!empty($field_content)) {
          $field_key = strtr($key, '_', '-');
          $region_content .= theme('nd_field', $field_content, $field_key, $node->nd_fields[$key]);
        }
        unset($node->content[$key]);
      }

      // Render region.
      if (!empty($region_content)) {
        if ($region_name == 'left' || $region_name == 'right') {
          $region_classes[$region_name] = $region_name;
        }
        $themed_regions[$region_name] = array(
          'content' => $region_content,
        );
      }
    }
  }
  $node_display = new stdClass();
  $node_display->all_regions = $all_regions;
  $node_display->themed_regions = $themed_regions;
  $node_display->region_classes = $region_classes;

  // Plugins.
  nd_plugins_process($vars, $node_display, $nd_display_settings);

  // Add classes based on node regions.
  $nd_middle_classes = 'no-sidebars';
  if (isset($node_display->region_classes['left']) && isset($node_display->region_classes['right'])) {
    $nd_middle_classes = 'two-sidebars';
  }
  elseif (isset($node_display->region_classes['left'])) {
    $nd_middle_classes = 'one-sidebar sidebar-left';
  }
  elseif (isset($node_display->region_classes['right'])) {
    $nd_middle_classes = 'one-sidebar sidebar-right';
  }

  // Build the $content variable.
  $content = '';
  foreach ($node_display->themed_regions as $region_name => $region_data) {
    $content .= '<div class="nd-region-' . $region_name;
    if ($region_name == 'middle') {
      $content .= ' ' . $nd_middle_classes;
    }
    if (isset($region_data['extra_class'])) {
      $content .= $region_data['extra_class'];
    }
    $content .= '" ';
    if (isset($region_data['inline_css'])) {
      $content .= $region_data['inline_css'];
    }
    $content .= '><div class="nd-region-inner">' . $region_data['content'] . '</div></div>';
  }
  $vars['content'] = $content;
}