function fieldgroup_build_content in Content Construction Kit (CCK) 6.2
Same name and namespace in other branches
- 6.3 modules/fieldgroup/fieldgroup.module \fieldgroup_build_content()
Build the node content element needed to render a fieldgroup.
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 content for fields required for the group.
$teaser:
$page: Similar to hook_nodeapi('view').
See also
2 calls to fieldgroup_build_content()
- fieldgroup_nodeapi in modules/
fieldgroup/ fieldgroup.module - Implementation of hook_nodeapi().
- fieldgroup_view_group in modules/
fieldgroup/ fieldgroup.module - Render a single field group, fully themed with label.
File
- modules/
fieldgroup/ fieldgroup.module, line 570 - Create field groups for CCK fields.
Code
function fieldgroup_build_content($group, &$node, $teaser, $page) {
// NODE_BUILD_NORMAL is 0, and ('whatever' == 0) is TRUE, so we need a ===.
if ($node->build_mode === NODE_BUILD_NORMAL || $node->build_mode == NODE_BUILD_PREVIEW) {
$context = $teaser ? 'teaser' : 'full';
}
else {
$context = $node->build_mode;
}
$group_name = $group['group_name'];
// Do not include group labels when indexing content.
if ($context == NODE_BUILD_SEARCH_INDEX) {
$group['settings']['display']['label'] = 'hidden';
}
$label = $group['settings']['display']['label'] == 'above';
$element = array(
'#title' => $label ? check_plain(t($group['label'])) : '',
'#description' => $label & !empty($group['settings']['display']['description']) ? content_filter_xss(t($group['settings']['display']['description'])) : '',
);
$format = isset($group['settings']['display'][$context]['format']) ? $group['settings']['display'][$context]['format'] : 'fieldset';
switch ($format) {
case 'simple':
$element['#type'] = 'fieldgroup_simple';
$element['#group_name'] = $group_name;
$element['#node'] = $node;
break;
case 'hidden':
$element['#access'] = FALSE;
break;
case 'fieldset_collapsed':
$element['#collapsed'] = TRUE;
case 'fieldset_collapsible':
$element['#collapsible'] = TRUE;
case 'fieldset':
$element['#type'] = 'fieldgroup_fieldset';
$element['#attributes'] = array(
'class' => 'fieldgroup ' . strtr($group['group_name'], '_', '-'),
);
break;
}
foreach ($group['fields'] as $field_name => $field) {
if (isset($node->content[$field_name])) {
$element[$field_name] = $node->content[$field_name];
}
}
// Allow other modules to alter the group view.
// Can't use module_invoke_all because we want
// to be able to use a reference to $node and $element.
foreach (module_implements('fieldgroup_view') as $module) {
$function = $module . '_fieldgroup_view';
$function($node, $element, $group, $context);
}
// Unset the original field values now that we've moved them.
foreach ($group['fields'] as $field_name => $field) {
if (isset($node->content[$field_name])) {
unset($node->content[$field_name]);
}
}
// The wrapper lets us get the themed output for the group
// to populate the $GROUP_NAME_rendered variable for node templates,
// and hide it from the $content variable if needed.
// See fieldgroup_preprocess_node(), theme_fieldgroup_wrapper().
$wrapper = array(
'group' => $element,
'#weight' => $group['weight'],
'#post_render' => array(
'fieldgroup_wrapper_post_render',
),
'#group_name' => $group_name,
'#type_name' => $node->type,
'#context' => $context,
);
$node->content[$group_name] = $wrapper;
}