You are here

function field_group_build_entity_groups in Field Group 8.3

Same name and namespace in other branches
  1. 8 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()

Pre-render callback for entity views.

Parameters

preprocess $vars: Variables.

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

Return value

array With re-arranged fields in groups.

See also

field_group_theme_registry_alter

field_group_fields_nest()

1 call to field_group_build_entity_groups()
FormatterHelper::entityViewPrender in src/FormatterHelper.php
Pre render callback for rendering groups on entities without theme hook.
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 578
Allows administrators to attach field groups.

Code

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

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

  // Use other nest function if field layout is active.
  if (isset($element['_field_layout'])) {
    field_group_field_layout_fields_nest($element, $nest_vars, $context);
  }
  else {
    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);

  // 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.
  $render_key = field_group_get_content_element_key($context);
  foreach ($element['#fieldgroups'] as $group) {
    if (!empty($element[$group->group_name])) {
      if (isset($vars[$render_key])) {

        // Field layout enabled? Place it in correct region of the
        // _field_layout key.
        if (isset($vars[$render_key]['_field_layout'])) {
          $vars[$render_key]['_field_layout'][$group->region][$group->group_name] = $element[$group->group_name];
        }
        else {
          $vars[$render_key][$group->group_name] = $element[$group->group_name];
        }
      }
    }
  }
}