You are here

function field_group_field_info_max_weight in Field Group 8

Same name and namespace in other branches
  1. 8.3 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 140
Allows administrators to attach custom fields to fieldable types.

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 type.
  $key = $entity_type . ':' . $bundle . ':' . $context . ':' . $context_mode;

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

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

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