function hook_field_info_max_weight

Same name in other branches
  1. 7.x modules/field/field.api.php \hook_field_info_max_weight()
  2. 8.9.x core/modules/field/field.api.php \hook_field_info_max_weight()
  3. 10 core/modules/field/field.api.php \hook_field_info_max_weight()
  4. 11.x core/modules/field/field.api.php \hook_field_info_max_weight()

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

1 invocation of hook_field_info_max_weight()
EntityDisplayBase::getHighestWeight in core/lib/Drupal/Core/Entity/EntityDisplayBase.php
Gets the highest weight of the components in the display.

File

core/modules/field/field.api.php, line 519

Code

function hook_field_info_max_weight($entity_type, $bundle, $context, $context_mode) {
    $weights = [];
    foreach (my_module_entity_additions($entity_type, $bundle, $context, $context_mode) as $addition) {
        $weights[] = $addition['weight'];
    }
    return $weights ? max($weights) : NULL;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.