W3cubDocs

/Drupal 8

function hook_field_info_max_weight

hook_field_info_max_weight($entity_type, $bundle, $context, $context_mode)

Returns the maximum weight for the entity components handled by the module.

Field API takes care of fields and 'extra_fields'. This hook is intended for third-party modules adding other entity components (e.g. field_group).

Parameters

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

string $bundle: The bundle name.

string $context: The context for which the maximum weight is requested. Either 'form' or 'display'.

string $context_mode: The view or form mode name.

Return value

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

Related topics

Hooks
Define functions that alter the behavior of Drupal core.

File

core/modules/field/field.api.php, line 259
Field API documentation.

Code

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

  foreach (my_module_entity_additions($entity_type, $bundle, $context, $context_mode) as $addition) {
    $weights[] = $addition['weight'];
  }

  return $weights ? max($weights) : NULL;
}

© 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/core!modules!field!field.api.php/function/hook_field_info_max_weight/8.1.x