You are here

function fieldgroup_view_group in Content Construction Kit (CCK) 6.2

Same name and namespace in other branches
  1. 6.3 modules/fieldgroup/fieldgroup.module \fieldgroup_view_group()

Render a single field group, fully themed with label.

To be used by third-party code (Panels, ...) that needs to output an isolated field group. Do *not* use inside node templates, use the $GROUP_NAME_rendered variables instead. You can also use the 'simple' style format and override the template fieldgroup-simple.tpl.php.

By default, the field group is displayed using the settings defined for the 'full node' or 'teaser' contexts (depending on the value of the $teaser param). Set $node->build_mode to a different value to use a different context.

Different settings can be specified by adjusting $group['settings']['display'].

Parameters

$group: The field group definition.

$node: The node containing the field group to display. Can be a 'pseudo-node', containing at least 'type', 'nid', 'vid', and the field data required for the group.

$teaser:

$page: Similar to hook_nodeapi('view').

Return value

The themed output for the field group.

See also

content_view_field()

1 call to fieldgroup_view_group()
fieldgroup_content_fieldgroup_content_type_render in modules/fieldgroup/panels/content_types/content_fieldgroup.inc
Output function for the 'fieldgroup' content type.

File

modules/fieldgroup/fieldgroup.module, line 675
Create field groups for CCK fields.

Code

function fieldgroup_view_group($group, &$node, $teaser = FALSE, $page = FALSE) {
  $group_name = $group['group_name'];
  $field_types = _content_field_types();

  // Clone the node to prevent from altering the original.
  $node_copy = drupal_clone($node);

  // Use 'full'/'teaser' if not specified otherwise.
  $node_copy->build_mode = isset($node_copy->build_mode) ? $node_copy->build_mode : NODE_BUILD_NORMAL;

  // Build the content element for individual fields in the field group.
  if (!isset($node_copy->content)) {
    $node_copy->content = array();
  }
  foreach (array_keys($group['fields']) as $field_name) {
    $field = content_fields($field_name, $node_copy->type);
    if (isset($node_copy->{$field_name})) {
      $items = $node_copy->{$field_name};

      // One-field equivalent to _content_field_invoke('sanitize').
      $module = $field_types[$field['type']]['module'];
      $function = $module . '_field';
      if (function_exists($function)) {
        $function('sanitize', $node_copy, $field, $items, $teaser, $page);
        $node_copy->{$field_name} = $items;
      }
      $field_view = content_field('view', $node_copy, $field, $items, $teaser, $page);

      // content_field('view') adds a wrapper to handle variables and 'excluded'
      // fields for node templates. We bypass it and get the actual field.
      $node_copy->content[$field_name] = $field_view[$field_name];
    }
  }

  // Build the content element of the field group itself.
  fieldgroup_build_content($group, $node_copy, $teaser, $page);

  // fieldgroup_build_content() adds a wrapper to handle variables and 'excluded'
  // groups for node templates. We bypass it and render the actual field group.
  $output = drupal_render($node_copy->content[$group_name]['group']);
  return $output;
}