function fieldgroup_nodeapi in Content Construction Kit (CCK) 6.3
Same name and namespace in other branches
- 5 fieldgroup.module \fieldgroup_nodeapi()
- 6 modules/fieldgroup/fieldgroup.module \fieldgroup_nodeapi()
- 6.2 modules/fieldgroup/fieldgroup.module \fieldgroup_nodeapi()
Implementation of hook_nodeapi().
File
- modules/
fieldgroup/ fieldgroup.module, line 725 - Create field groups for CCK fields.
Code
function fieldgroup_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
switch ($op) {
case 'view':
// Prevent against invalid 'nodes' built by broken 3rd party code.
if (isset($node->type)) {
//prepare data that will make this easier
$group_rows = array();
$field_rows = array();
$groups = fieldgroup_groups($node->type);
if (!empty($groups)) {
foreach ($groups as $name => $more) {
$group_rows[] = $name;
}
}
$fields = $node->content;
if (!empty($fields)) {
foreach ($fields as $name => $more) {
if (is_string($name) && strstr($name, 'field_')) {
$field_rows[] = $name;
}
}
}
$max_depth = fieldgroup_order_fields_groups($group_rows, $groups, $field_rows);
//cover the top level fields that aren't in fieldgroups
if (isset($field_rows)) {
foreach ($field_rows as $name) {
$node->content[$name]['#depth'] = 0;
}
}
// Build the node content element needed to render each fieldgroup.
foreach ($groups as $group) {
fieldgroup_build_content($group, $node, $teaser, $page);
}
//reorder the groups from the inside-out in order to avoid writing a recursive function
while ($max_depth >= 0) {
foreach ($group_rows as $name) {
if (!empty($node->content[$name]) && $node->content[$name]['#depth'] == $max_depth) {
$parent = $node->content[$name]['#group_parent'];
if (isset($parent) && $parent != '') {
$node->content[$parent]['group'][$name] = $node->content[$name];
unset($node->content[$name]);
}
}
}
$max_depth--;
}
}
break;
}
}