function field_info_max_weight

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 view mode.

Return value

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

Related topics

2 calls to field_info_max_weight()
FieldOverview::form in drupal/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php
Overrides Drupal\field_ui\OverviewBase::form().
_field_write_instance in drupal/core/modules/field/field.crud.inc
Stores an instance record in the field configuration database.

File

drupal/core/modules/field/field.info.inc, line 542
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;
}