1.20.x field.info.inc field_info_max_weight($entity_type, $bundle, $context)

Returns the maximum weight of all the components in an entity.

This includes fields, 'extra_fields', and other components added by third-party modules (e.g. field_group).

Parameters

$entity_type: The type of entity; e.g. 'node' or 'user'.

$bundle: The bundle name.

$context: The context for which the maximum weight is requested. Either 'form', or the name of a display mode.

Return value

The maximum weight of the entity's components, or NULL if no components: were found.

Related topics

File

modules/field/field.info.inc, line 858
Field Info API, providing information about available fields and field types.

Code

function field_info_max_weight($entity_type, $bundle, $context) {
  $weights = array();

  // Collect weights for fields.
  foreach (field_info_instances($entity_type, $bundle) as $instance) {
    if ($context == 'form') {
      $weights[] = $instance['widget']['weight'];
    }
    elseif (isset($instance['display'][$context]['weight'])) {
      $weights[] = $instance['display'][$context]['weight'];
    }
  }
  // Collect weights for extra fields.
  foreach (field_info_extra_fields($entity_type, $bundle, $context) as $extra) {
    $weights[] = $extra['weight'];
  }

  // Let other modules feedback about their own additions.
  $weights = array_merge($weights, module_invoke_all('field_info_max_weight', $entity_type, $bundle, $context));
  $max_weight = $weights ? max($weights) : NULL;

  return $max_weight;
}