You are here

function field_group_field_info_max_weight in Field Group 8.3

Same name and namespace in other branches
  1. 8 field_group.module \field_group_field_info_max_weight()
  2. 7.2 field_group.field_ui.inc \field_group_field_info_max_weight()
  3. 7 field_group.field_ui.inc \field_group_field_info_max_weight()

Implements hook_field_info_max_weight().

File

./field_group.module, line 207
Allows administrators to attach field groups.

Code

function field_group_field_info_max_weight($entity_type, $bundle, $context, $context_mode) {

  // Prevent recursion.
  // @see https://www.drupal.org/project/drupal/issues/2966137
  static $recursion_tracker = [];

  // Track the entity display.
  $key = $entity_type . ':' . $bundle . ':' . $context . ':' . $context_mode;

  // If entity display check was attempted but did not finish, do not continue.
  if (isset($recursion_tracker[$key])) {
    return NULL;
  }

  // Mark this as an attempt at entity display check.
  $recursion_tracker[$key] = TRUE;
  $groups = field_group_info_groups($entity_type, $bundle, $context, $context_mode);

  // Remove the indicator once the entity display is successfully checked.
  unset($recursion_tracker[$key]);
  $weights = [];
  foreach ($groups as $group) {
    $weights[] = $group->weight;
  }
  return $weights ? max($weights) : NULL;
}