function field_info_max_weight in Drupal 7
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()
- field_ui_field_overview_form in modules/
field_ui/ field_ui.admin.inc - Form constructor for the 'Manage fields' form of a bundle.
- _field_write_instance in modules/
field/ field.crud.inc - Stores an instance record in the field configuration database.
File
- modules/
field/ field.info.inc, line 712 - 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;
}