function hook_field_attach_form

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.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for which an edit form is being built.

$form: The form structure 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

1 invocation of hook_field_attach_form()
field_attach_form in drupal/core/modules/field/field.attach.inc
Adds form elements for all fields for an entity to a form structure.

File

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

Code

function hook_field_attach_form(\Drupal\Core\Entity\EntityInterface $entity, &$form, &$form_state, $langcode) {

  // Add a checkbox allowing a given field to be emptied.
  // See hook_field_attach_extract_form_values() for the corresponding
  // processing code.
  $form['empty_field_foo'] = array(
    '#type' => 'checkbox',
    '#title' => t("Empty the 'field_foo' field"),
  );
}