I'm trying to use the fieldgroup_view_group function to print a multigroup inside a block.
The fieldgroup_view_group function looks like this:
<?php
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;
}
?>
And example of the function being used is like this:
<?php
function content_multigroup_content_multigroup_content_type_render($subtype, $conf, $panel_args, $context) {
if (!isset($context->data)) {
return;
}
$node = drupal_clone($context->data);
// Extract the node type and fieldgroup name from the subtype.
list($node_type, $group_name) = explode(':', $subtype, 2);
// Get a list of all fieldgroups for this node type.
$groups = fieldgroup_groups($node_type);
if (!isset($groups[$group_name])) {
return;
}
$group = $groups[$group_name];
// Render the field group.
$node->build_mode = NODE_BUILD_NORMAL;
$group['settings']['display']['label'] = $conf['label'] == 'normal' || !empty($conf['override_title']) ? 'hidden' : $conf['label'];
$group['settings']['display']['full']['format'] = $conf['format'];
$group['settings']['display']['full']['exclude'] = 0;
$group['settings']['multigroup']['subgroup']['full']['format'] = $conf['subgroup'];
$group['settings']['multigroup']['subgroup']['full']['exclude'] = 0;
$output = fieldgroup_view_group($group, $node);
$block = new stdClass();
if ($conf['label'] == 'normal') {
$block->title = t($group['label']);
}
$block->content = !empty($output) ? $output : $conf['empty'];
return $block;
}
?>
Can somebody show me how to print one multigroup using this function? (And then I can hopefully figure out how to print the rest of my groups.)
Thanks.