field_info_max_weight
function field_info_max_weight
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 view 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 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; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!field!field.info.inc/function/field_info_max_weight/7.x