function hook_field_widget_properties_alter

Alters the widget properties of a field instance before it gets displayed.

Note that instead of hook_field_widget_properties_alter(), which is called for all fields on all entity types, hook_field_widget_properties_ENTITY_TYPE_alter() may be used to alter widget properties for fields on a specific entity type only.

This hook is called once per field per added or edit entity. If the result of the hook involves reading from the database, it is highly recommended to statically cache the information.

Parameters

array $widget_properties: The instance's widget properties.

array $context: An associative array containing:

  • entity_type: The entity type, e.g., 'node' or 'user'.
  • bundle: The bundle, e.g., 'page' or 'article'.
  • field: The field that the widget belongs to.
  • instance: The instance of the field.

See also

hook_field_widget_properties_ENTITY_TYPE_alter()

Related topics

1 function implements hook_field_widget_properties_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

field_test_field_widget_properties_alter in drupal/core/modules/field/tests/modules/field_test/field_test.module
Implements hook_field_widget_properties_alter().

File

drupal/core/modules/field/field.api.php, line 816

Code

function hook_field_widget_properties_alter(array &$widget_properties, array $context) {

  // Change a widget's type according to the time of day.
  $field = $context['field'];
  if ($context['entity_type'] == 'node' && $field['field_name'] == 'field_foo') {
    $time = date('H');
    $widget_properties['type'] = $time < 12 ? 'widget_am' : 'widget_pm';
  }
}