diff -u b/modules/field/field.api.php b/modules/field/field.api.php --- b/modules/field/field.api.php +++ b/modules/field/field.api.php @@ -675,11 +675,6 @@ * Widget hooks are typically called by the Field Attach API during the * creation of the field form structure with field_attach_form(). * - * @see hook_field_widget_info_alter() - * @see hook_field_widget_form() - * @see hook_field_widget_form_alter() - * @see hook_field_widget_error() - * * @return * An array describing the widget types implemented by the module. * The keys are widget type names. To avoid name clashes, widget type @@ -705,6 +700,12 @@ * - FIELD_BEHAVIOR_DEFAULT: (default) If the widget accepts default * values. * - FIELD_BEHAVIOR_NONE: if the widget does not support default values. + * + * @see hook_field_widget_info_alter() + * @see hook_field_widget_form() + * @see hook_field_widget_form_alter() + * @see hook_field_widget_WIDGET_TYPE_form_alter() + * @see hook_field_widget_error() */ function hook_field_widget_info() { return array( @@ -784,9 +785,6 @@ * properties from $field and $instance and set them as ad-hoc * $element['#custom'] properties, for later use by its element callbacks. * - * @see field_widget_field() - * @see field_widget_instance() - * * Other modules may alter the form element provided by this function using * hook_field_widget_form_alter(). * @@ -830,6 +828,11 @@ * * @return * The form elements for a single widget for this field. + * + * @see field_widget_field() + * @see field_widget_instance() + * @see hook_field_widget_form_alter() + * @see hook_field_widget_WIDGET_TYPE_form_alter() */ function hook_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) { $element += array( @@ -847,15 +850,19 @@ * @param $form_state * An associative array containing the current state of the form. * @param $context - * An associative array containing additional information about the current - * field widget: - * - field: The field structure. - * - instance: The field instance structure. - * - form: The form structure where widgets are being attached. - * This might be a full form structure, or a sub-element of a larger form. + * An associative array containing the follwoing key-value pairs, matching the + * arguments received by hook_field_widget_form(): + * - "form": The form structure where widgets are being attached to. This + * might be a full form structure, or a sub-element of a larger form. + * - "field": The field structure. + * - "instance": The field instance structure. + * - "langcode": The language associated with $items. + * - "items": Array of default values for this field. + * - "delta": The order of this item in the array of subelements (0, 1, 2, + * etc). * * @see hook_field_widget_form() - * @see hook_form_alter() + * @see hook_field_widget_WIDGET_TYPE_form_alter */ function hook_field_widget_form_alter(&$element, &$form_state, $context) { // Add a css class to widget form elements for all fields of type mytype. @@ -868,7 +875,7 @@ /** * Alter widget forms for a specific widget provided by another module. * - * Modules can implement hook_field_widget_NAME_form_alter() to modify a + * Modules can implement hook_field_widget_WIDGET_TYPE_form_alter() to modify a * specific widget form, rather than using hook_field_widget_form_alter() and * checking the widget type. * @@ -877,21 +884,24 @@ * @param $form_state * An associative array containing the current state of the form. * @param $context - * An associative array containing additional information about the current - * field widget: - * - field: The field structure. - * - instance: The field instance structure. - * - form: The form structure where widgets are being attached. - * This might be a full form structure, or a sub-element of a larger form. + * An associative array containing the follwoing key-value pairs, matching the + * arguments received by hook_field_widget_form(): + * - "form": The form structure where widgets are being attached to. This + * might be a full form structure, or a sub-element of a larger form. + * - "field": The field structure. + * - "instance": The field instance structure. + * - "langcode": The language associated with $items. + * - "items": Array of default values for this field. + * - "delta": The order of this item in the array of subelements (0, 1, 2, + * etc). * - * @see hook_field_widget_form_alter() * @see hook_field_widget_form() - * @see hook_form_alter() + * @see hook_field_widget_form_alter() */ -function hook_field_widget_NAME_form_alter(&$element, &$form_state, $context) { - // Code here will only act on the widget NAME. For example, if the widget - // name is mymodule_autocomplete, then the following will change the - // autocomplete path for the mymodule_autocomplete widget only. +function hook_field_widget_WIDGET_TYPE_form_alter(&$element, &$form_state, $context) { + // Code here will only act on widgets of type WIDGET_TYPE. For example, + // hook_field_widget_mymodule_autocomplete_form_alter() will only act on + // widgets of type 'mymodule_autocomplete'. $element['#autocomplete_path'] = 'mymodule/autocomplete_path'; } diff -u b/modules/field/field.form.inc b/modules/field/field.form.inc --- b/modules/field/field.form.inc +++ b/modules/field/field.form.inc @@ -78,8 +78,6 @@ if ($element = $function($form, $form_state, $field, $instance, $langcode, $items, $delta, $element)) { // Allow modules to alter the field widget form element. $context = array( - 'entity_type' => $entity_type, - 'entity' => $entity, 'form' => $form, 'field' => $field, 'instance' => $instance, @@ -209,7 +207,6 @@ // Allow modules to alter the field widget form element. $context = array( - 'entity_type' => $instance['entity_type'], 'form' => $form, 'field' => $field, 'instance' => $instance,