You are here

function field_group_build_entity_groups in Field Group 8

Same name and namespace in other branches
  1. 8.3 field_group.module \field_group_build_entity_groups()
  2. 7.2 field_group.module \field_group_build_entity_groups()
  3. 7 field_group.module \field_group_build_entity_groups()

Preprocess/ Pre-render callback.

Parameters

$vars preprocess vars or form element:

$context The display context (entity type, form or view):

Return value

$element Array with re-arranged fields in groups.

See also

field_group_form_pre_render()

field_group_theme_registry_alter

field_group_fields_nest()

2 calls to field_group_build_entity_groups()
field_group_entity_view_pre_render in ./field_group.module
Pre render callback for rendering groups on entities without theme hook.
field_group_form_pre_render in ./field_group.module
Pre render callback for rendering groups.
1 string reference to 'field_group_build_entity_groups'
field_group_theme_registry_alter in ./field_group.module
Implements hook_theme_registry_alter().

File

./field_group.module, line 373
Allows administrators to attach custom fields to fieldable types.

Code

function field_group_build_entity_groups(&$vars, $context = 'view') {
  if ($context == 'form') {
    $element =& $vars;
    $nest_vars = NULL;
  }
  else {
    if (isset($vars['elements'])) {
      $element =& $vars['elements'];
    }
    elseif (isset($vars['content'])) {
      $element =& $vars['content'];
    }
    else {
      if ($context === 'eck_entity') {
        $element =& $vars['entity'];
      }
      else {
        $element =& $vars;
      }
    }
    $nest_vars =& $vars;
  }

  // No groups on the entity.
  if (empty($element['#fieldgroups'])) {
    return $element;
  }

  // Nest the fields in the corresponding field groups.
  field_group_fields_nest($element, $nest_vars, $context);

  // Allow others to alter the pre_rendered build.
  Drupal::moduleHandler()
    ->alter('field_group_build_pre_render', $element);

  // Return the element on forms.
  if ($context == 'form') {
    return $element;
  }

  // No groups on the entity. Prerender removed empty field groups.
  if (empty($element['#fieldgroups'])) {
    return $element;
  }

  // Put groups inside content if we are rendering an entity_view.
  foreach ($element['#fieldgroups'] as $group) {
    if (!empty($element[$group->group_name])) {
      $key = field_group_get_content_element_key($context);
      if (isset($vars[$key])) {
        $vars[$key][$group->group_name] = $element[$group->group_name];
      }
    }
  }
}