diff -u modules/field/field.api.php modules/field/field.api.php --- modules/field/field.api.php +++ modules/field/field.api.php @@ -809,7 +809,12 @@ * - #bundle: The name of the field bundle the field is contained in. * - #field_name: The name of the field. * - #language: The language the field is being edited in. - * - #field_parents: The '#parents' space for the field in the form. + * - #field_parents: The 'parents' space for the field in the form. Most + * widgets can simply overlook this property. This identifies the + * location where the field values are placed within + * $form_state['values'], and is used to access processing information + * for the field through the field_form_get_state() and + * field_form_set_state() functions. * - #columns: A list of field storage columns of the field. * - #title: The sanitized element label for the field instance, ready for * output. diff -u modules/field/field.attach.inc modules/field/field.attach.inc --- modules/field/field.attach.inc +++ modules/field/field.attach.inc @@ -478,7 +478,9 @@ * $langcode => array( * '#field_name' => The name of the field, * '#language' => $langcode, - * '#field_parents' => The '#parents' space for the field in the form, + * '#field_parents' => The 'parents' space for the field in the form, + * equal to the #parents property of the $form parameter received by + * field_attach_form(), * '#required' => Whether or not the field is required, * '#title' => The label of the field instance, * '#description' => The description text for the field instance, @@ -491,7 +493,9 @@ * '#entity_type' => The name of the entity type, * '#bundle' => The name of the bundle, * '#field_name' => The name of the field, - * '#field_parents' => The '#parents' space for the field in the form, + * '#field_parents' => The 'parents' space for the field in the form, + * equal to the #parents property of the $form parameter received by + * field_attach_form(), * '#title' => The title to be displayed by the widget, * '#default_value' => The field value for delta 0, * '#required' => Whether the widget should be marked required, diff -u modules/field/field.form.inc modules/field/field.form.inc --- modules/field/field.form.inc +++ modules/field/field.form.inc @@ -309,10 +309,12 @@ } /** - * #after_build callback for field_default_form() to store information about the form structure. + * #after_build callback for field elements in a form. + * + * This stores the final location of the field within the form structure so + * that field_default_form_errors() can assign validation errors to the right + * form element. * - * The 'array_parents' array is used to assign validation errors to actual form - * elements. * @see field_default_form_errors() */ function field_form_element_after_build($element, &$form_state) { @@ -438,15 +440,15 @@ * - instance: the field instance definition array, * - items_count: the number of widgets to display for the field, * - array_parents: the location of the field's widgets within the $form - * structure. This entry is populated at '#fter_build' time. + * structure. This entry is populated at '#after_build' time. * - errors: the array of field validation errors reported on the field. This * entry is populated at field_attach_form_validate() time. * * @see field_form_set_state() */ function field_form_get_state($parents, $field_name, $langcode, &$form_state) { - $field_parents = _field_form_state_parents($parents, $field_name, $langcode); - return drupal_array_get_nested_value($form_state, $field_parents); + $form_state_parents = _field_form_state_parents($parents, $field_name, $langcode); + return drupal_array_get_nested_value($form_state, $form_state_parents); } /** @@ -467,12 +469,12 @@ * @see field_form_get_state() */ function field_form_set_state($parents, $field_name, $langcode, &$form_state, $field_state) { - $field_parents = _field_form_state_parents($parents, $field_name, $langcode); - drupal_array_set_nested_value($form_state, $field_parents, $field_state); + $form_state_parents = _field_form_state_parents($parents, $field_name, $langcode); + drupal_array_set_nested_value($form_state, $form_state_parents, $field_state); } /** - * Internal helper function: defines the location of field information within $form_state + * Returns the location of processing information within $form_state. */ function _field_form_state_parents($parents, $field_name, $langcode) { // To ensure backwards compatibility on regular entity forms for widgets that @@ -485,14 +487,14 @@ // @todo Remove backwards compatibility in Drupal 8, and use a unique // $form_state['field'][...$parents...]['#fields'][$field_name] structure. if (!empty($parents)) { - $field_parents = array_merge(array('#parents'), $parents, array('#fields')); + $form_state_parents = array_merge(array('#parents'), $parents, array('#fields')); } else { - $field_parents = array(); + $form_state_parents = array(); } - $field_parents = array_merge(array('field'), $field_parents, array($field_name, $langcode)); + $form_state_parents = array_merge(array('field'), $form_state_parents, array($field_name, $langcode)); - return $field_parents; + return $form_state_parents; } /**