| 1 field_group.api.php | hook_field_group_pre_render(array &$element, $group, array &$form) |
Implements hook_field_group_pre_render().
This function gives you the opportunity to create the given wrapper element that can contain the fields. In the example beneath, some variables are prepared and used when building the actual wrapper element. All elements in Backdrop Form API can be used.
Note that at this point, the field group has no notion of the fields in it.
There is also an alternative way of handling this. The default implementation within field_group calls "field_group_pre_render_<format_type>".
Parameters
array $element: Elements by address.
object $group: The field group info.
array $form: The form array.
See also
field_group_pre_render_fieldset()
Related topics
File
- core/
modules/ field_group/ field_group.api.php, line 233 - Hooks provided by the Field Group module.
Code
function hook_field_group_pre_render(array &$element, $group, array &$form) {
// You can prepare some variables to use in the logic.
$view_mode = isset($form['#view_mode']) ? $form['#view_mode'] : 'form';
$id = $form['#entity_type'] . '_' . $form['#bundle'] . '_' . $view_mode . '_' . $group->group_name;
$classes = '';
// Each formatter type can have whole different set of element properties.
switch ($group->format_type) {
// Normal or collapsible div.
case 'div':
$effect = isset($group->format_settings['instance_settings']['effect']) ? $group->format_settings['instance_settings']['effect'] : 'none';
$speed = isset($group->format_settings['instance_settings']['speed']) ? $group->format_settings['instance_settings']['speed'] : 'none';
$add = array(
'#type' => 'markup',
'#weight' => $group->weight,
'#id' => $id,
);
$classes .= " speed-$speed effect-$effect";
if ($group->format_settings['formatter'] != 'open') {
$add['#prefix'] = '<div class="field-group-format ' . $classes . '">
<span class="field-group-format-toggler">' . check_plain(t($group->label)) . '</span>
<div class="field-group-format-wrapper" style="display: none;">';
$add['#suffix'] = '</div></div>';
}
else {
$add['#prefix'] = '<div class="field-group-format ' . $group->group_name . ' ' . $classes . '">';
$add['#suffix'] = '</div>';
}
if (!empty($description)) {
$add['#prefix'] .= '<div class="description">' . $description . '</div>';
}
$element += $add;
if ($effect == 'blind') {
backdrop_add_library('system', 'effects.blind');
}
break;
}
}