1 field.api.php hook_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode)

Act on field_attach_form().

This hook is invoked after the field module has performed the operation. Implementing modules should alter the $form or $form_state parameters.


$entity_type: The type of $entity; for example, 'node' or 'user'.

$entity: The entity for which an edit form is being built.

$form: The form structure where field elements are attached to. This might be a full form structure, or a sub-element of a larger form. The $form['#parents'] property can be used to identify the corresponding part of $form_state['values']. Hook implementations that need to act on the top-level properties of the global form (like #submit, #validate...) can add a #process callback to the array received in the $form parameter, and act on the $complete_form parameter in the process callback.

$form_state: An associative array containing the current state of the form.

$langcode: The language the field values are going to be entered in. If no language is provided the default site language will be used.

Related topics


core/modules/field/field.api.php, line 1348
Hooks provided by the Field module.


function hook_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {
  // Add a checkbox allowing a given field to be emptied.
  // See hook_field_attach_submit() for the corresponding processing code.
  $form['empty_field_foo'] = array(
    '#type' => 'checkbox',
    '#title' => t("Empty the 'field_foo' field"),