1

field_group.module defines a function as follows:

function field_group_pre_render_accordion_item(&$element, $group, &$form) {
  $element += array(
    '#type' => 'markup',
    '#prefix' => '<h3 class="field-group-format-toggler ' . $group->format_type . ($group->collapsed ? '' : ' field-group-accordion-active') . '"><a href="#">' . check_plain(t($group->label)) . '</a></h3>
    <div class="field-group-format-wrapper ' . $group->classes . '">',
    '#suffix' => '</div>',
    //'#attributes' => array('class' => array($group->format_type)),
  );
  if (!empty($group->description)) {
    $element['#prefix'] .= '<div class="description">' . $group->description . '</div>';
  }
}

Which is an instance of field_group_pre_render_<format-type>.

What I want to do is change that prefix code from an h3 to a div. But I'm not sure what the appropriate function/hook would be to use.

The Field Group API defines a hook_field_group_pre_render function but the $element argument in this function doesn't supply the #prefix element - so I'm not sure.

Ideally I could just totally override the function field_group_pre_render_accordion_item in my own code...

2
  • 1
    Could you please try hook_field_group_pre_render_alter?
    – Andrew
    Jul 1, 2015 at 10:21
  • I actually laid out every relevant hook, including that one and the aforementioned hook and hook_field_group_build_pre_render_alter are the only ones that fire - none of these hooks contain the correct info. There has to be a way to directly override the function, I think.
    – njp
    Jul 1, 2015 at 10:43

1 Answer 1

3

Implementing hook_field_group_pre_render_alter() seems the way to go, it's called just after field_group_field_group_pre_render() which calls field_group_pre_render_accordion_item() and receives the correct info.

It should be like this:

function mymodule_field_group_pre_render_alter(&$element, $group, &$form) {
  if ($group->format_type == 'accordion_item') {
    $element['#prefix'] = '<div class="field-group-format-toggler ' . $group->format_type . ($group->collapsed ? '' : ' field-group-accordion-active') . '"><a href="#">' . check_plain(t($group->label)) . '</a></div><div class="field-group-format-wrapper ' . $group->classes . '">';
    if (!empty($group->description)) {
      $element['#prefix'] .= '<div class="description">' . $group->description . '</div>';
    }
  }
}

Remember to implement it in a module, as a hook_*_alter() implemented in a front-end theme may not be discovered while flushing cache via drush or in the back-end theme.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.