diff --git a/core/lib/Drupal/Core/Entity/EntityFormController.php b/core/lib/Drupal/Core/Entity/EntityFormController.php index 9ed56e5..147baff 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormController.php +++ b/core/lib/Drupal/Core/Entity/EntityFormController.php @@ -305,10 +305,9 @@ public function validate(array $form, array &$form_state) { // Map errors back to form elements. if ($violations) { foreach ($violations as $field_name => $field_violations) { - $langcode = field_is_translatable($entity_type , field_info_field($entity_type, $field_name)) ? $entity_langcode : Language::LANGCODE_NOT_SPECIFIED; - $field_state = field_form_get_state($form['#parents'], $field_name, $langcode, $form_state); + $field_state = field_form_get_state($form['#parents'], $field_name, $form_state); $field_state['constraint_violations'] = $field_violations; - field_form_set_state($form['#parents'], $field_name, $langcode, $form_state, $field_state); + field_form_set_state($form['#parents'], $field_name, $form_state, $field_state); } field_invoke_method('flagErrors', _field_invoke_widget_target($form_state['form_display']), $entity, $form, $form_state); diff --git a/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php b/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php index fd439b0..1477e46 100644 --- a/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php +++ b/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php @@ -133,7 +133,7 @@ protected function buildEntity(array $form, array &$form_state) { */ protected function simplify(array &$form, array &$form_state) { $field_name = $form_state['field_name']; - $widget_element =& $form[$field_name]['wrapper']; + $widget_element =& $form[$field_name]['widget']; // Hide the field label from displaying within the form, because JavaScript // displays the equivalent label that was provided within an HTML data diff --git a/core/modules/field/field.deprecated.inc b/core/modules/field/field.deprecated.inc index b018c7b..8ac601e 100644 --- a/core/modules/field/field.deprecated.inc +++ b/core/modules/field/field.deprecated.inc @@ -486,7 +486,7 @@ function field_read_instances($conditions = array(), $include_additional = array * 'field_foo' => array( * '#access' => TRUE if the current user has 'edit' grants for the field, * FALSE if not. - * 'wrapper' => array( + * 'widget' => array( * '#field_name' => The name of the field, * '#language' => $langcode, * '#field_parents' => The 'parents' space for the field in the form, @@ -629,10 +629,9 @@ function field_attach_form_validate(EntityInterface $entity, $form, &$form_state $has_violations = TRUE; // Place violations in $form_state. - $langcode = field_is_translatable($entity->entityType(), field_info_field($entity->entityType(), $field_name)) ? $entity->language()->id : Language::LANGCODE_NOT_SPECIFIED; - $field_state = field_form_get_state($form['#parents'], $field_name, $langcode, $form_state); + $field_state = field_form_get_state($form['#parents'], $field_name, $form_state); $field_state['constraint_violations'] = $field_violations; - field_form_set_state($form['#parents'], $field_name, $langcode, $form_state, $field_state); + field_form_set_state($form['#parents'], $field_name, $form_state, $field_state); } } } diff --git a/core/modules/field/field.form.inc b/core/modules/field/field.form.inc index d71c4fd..1ba3e9c 100644 --- a/core/modules/field/field.form.inc +++ b/core/modules/field/field.form.inc @@ -125,11 +125,10 @@ function _field_sort_items_value_helper($a, $b) { function field_form_element_after_build($element, &$form_state) { $parents = $element['#field_parents']; $field_name = $element['#field_name']; - $langcode = $element['#language']; - $field_state = field_form_get_state($parents, $field_name, $langcode, $form_state); + $field_state = field_form_get_state($parents, $field_name, $form_state); $field_state['array_parents'] = $element['#array_parents']; - field_form_set_state($parents, $field_name, $langcode, $form_state, $field_state); + field_form_set_state($parents, $field_name, $form_state, $field_state); return $element; } @@ -149,13 +148,12 @@ function field_add_more_submit($form, &$form_state) { // Go one level up in the form, to the widgets container. $element = NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -1)); $field_name = $element['#field_name']; - $langcode = $element['#language']; $parents = $element['#field_parents']; // Increment the items count. - $field_state = field_form_get_state($parents, $field_name, $langcode, $form_state); + $field_state = field_form_get_state($parents, $field_name, $form_state); $field_state['items_count']++; - field_form_set_state($parents, $field_name, $langcode, $form_state, $field_state); + field_form_set_state($parents, $field_name, $form_state, $field_state); $form_state['rebuild'] = TRUE; } @@ -194,8 +192,6 @@ function field_add_more_js($form, $form_state) { * The array of #parents where the field lives in the form. * @param $field_name * The field name. - * @param $langcode - * The language in which the field values are entered. * @param $form_state * The form state. * @@ -209,8 +205,8 @@ function field_add_more_js($form, $form_state) { * * @see field_form_set_state() */ -function field_form_get_state($parents, $field_name, $langcode, &$form_state) { - $form_state_parents = _field_form_state_parents($parents, $field_name, $langcode); +function field_form_get_state($parents, $field_name, &$form_state) { + $form_state_parents = _field_form_state_parents($parents, $field_name); return NestedArray::getValue($form_state, $form_state_parents); } @@ -221,8 +217,6 @@ function field_form_get_state($parents, $field_name, $langcode, &$form_state) { * The array of #parents where the field lives in the form. * @param $field_name * The field name. - * @param $langcode - * The language in which the field values are entered. * @param $form_state * The form state. * @param $field_state @@ -231,8 +225,8 @@ function field_form_get_state($parents, $field_name, $langcode, &$form_state) { * * @see field_form_get_state() */ -function field_form_set_state($parents, $field_name, $langcode, &$form_state, $field_state) { - $form_state_parents = _field_form_state_parents($parents, $field_name, $langcode); +function field_form_set_state($parents, $field_name, &$form_state, $field_state) { + $form_state_parents = _field_form_state_parents($parents, $field_name); NestedArray::setValue($form_state, $form_state_parents, $field_state); } @@ -243,30 +237,14 @@ function field_form_set_state($parents, $field_name, $langcode, &$form_state, $f * The array of #parents where the field lives in the form. * @param $field_name * The field name. - * @param $langcode - * The language in which the field values are entered. * * @return * 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 - // still access $form_state['field'][$field_name] directly, - // - top-level fields (empty $parents) are placed directly under - // $form_state['fields'][$field_name]. - // - Other fields are placed under - // $form_state['field']['#parents'][...$parents...]['#fields'][$field_name] - // to avoid clashes between field names and $parents parts. - // @todo Remove backwards compatibility in Drupal 8, and use a unique - // $form_state['field'][...$parents...]['#fields'][$field_name] structure. - if (!empty($parents)) { - $form_state_parents = array_merge(array('#parents'), $parents, array('#fields')); - } - else { - $form_state_parents = array(); - } - $form_state_parents = array_merge(array('field'), $form_state_parents, array($field_name, $langcode)); - - return $form_state_parents; +function _field_form_state_parents($parents, $field_name) { + // Field processing data is placed at + // $form_state['field']['#parents'][...$parents...]['#fields'][$field_name], + // to avoid clashes between field names and $parents parts. + return array_merge(array('field', '#parents'), $parents, array('#fields', $field_name)); } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php index eb2e4db..4002dd5 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php @@ -103,9 +103,9 @@ public function defaultValuesFormValidate(array $element, array &$form, array &$ if (count($violations)) { // Store reported errors in $form_state. $field_name = $this->getFieldDefinition()->getFieldName(); - $field_state = field_form_get_state($element['#parents'], $field_name, $langcode, $form_state); + $field_state = field_form_get_state($element['#parents'], $field_name, $form_state); $field_state['constraint_violations'] = $violations; - field_form_set_state($element['#parents'], $field_name, $langcode, $form_state, $field_state); + field_form_set_state($element['#parents'], $field_name, $form_state, $field_state); // Assign reported errors to the correct form element. $widget->flagErrors($entity, $langcode, $this, $element, $form_state); diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php index 50e9039..e6839d3 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php @@ -61,13 +61,13 @@ public function form(EntityInterface $entity, $langcode, FieldInterface $items, $parents = $form['#parents']; // Store field information in $form_state. - if (!field_form_get_state($parents, $field_name, $langcode, $form_state)) { + if (!field_form_get_state($parents, $field_name, $form_state)) { $field_state = array( 'items_count' => count($items), 'array_parents' => array(), 'constraint_violations' => array(), ); - field_form_set_state($parents, $field_name, $langcode, $form_state, $field_state); + field_form_set_state($parents, $field_name, $form_state, $field_state); } // Collect widget elements. @@ -110,6 +110,7 @@ public function form(EntityInterface $entity, $langcode, FieldInterface $items, // in alter() hooks. $elements['#after_build'][] = 'field_form_element_after_build'; $elements['#field_name'] = $field_name; + // @todo Not strictly needed anymore. $elements['#language'] = $langcode; $elements['#field_parents'] = $parents; // Enforce the structure of submitted values. @@ -118,7 +119,6 @@ public function form(EntityInterface $entity, $langcode, FieldInterface $items, $elements += array('#tree' => TRUE); $return = array( - // @todo should we include the $field_name ourselves ? $field_name => array( // Aid in theming of widgets by rendering a classified container. '#type' => 'container', @@ -132,7 +132,7 @@ public function form(EntityInterface $entity, $langcode, FieldInterface $items, ), ), '#access' => $this->checkFieldAccess('edit', $entity), - 'wrapper' => $elements, + 'widget' => $elements, ), ); @@ -155,7 +155,7 @@ protected function formMultipleElements(EntityInterface $entity, FieldInterface // Determine the number of widgets to display. switch ($cardinality) { case FIELD_CARDINALITY_UNLIMITED: - $field_state = field_form_get_state($parents, $field_name, $langcode, $form_state); + $field_state = field_form_get_state($parents, $field_name, $form_state); $max = $field_state['items_count']; $is_multiple = TRUE; break; @@ -318,12 +318,12 @@ public function extractFormValues(EntityInterface $entity, $langcode, FieldInter $items->filterEmptyValues(); // Put delta mapping in $form_state, so that flagErrors() can use it. - $field_state = field_form_get_state($form['#parents'], $field_name, $langcode, $form_state); + $field_state = field_form_get_state($form['#parents'], $field_name, $form_state); foreach ($items as $delta => $item) { $field_state['original_deltas'][$delta] = $item->_original_delta; unset($item->_original_delta); } - field_form_set_state($form['#parents'], $field_name, $langcode, $form_state, $field_state); + field_form_set_state($form['#parents'], $field_name, $form_state, $field_state); } } @@ -333,7 +333,7 @@ public function extractFormValues(EntityInterface $entity, $langcode, FieldInter public function flagErrors(EntityInterface $entity, $langcode, FieldInterface $items, array $form, array &$form_state) { $field_name = $this->fieldDefinition->getFieldName(); - $field_state = field_form_get_state($form['#parents'], $field_name, $langcode, $form_state); + $field_state = field_form_get_state($form['#parents'], $field_name, $form_state); if (!empty($field_state['constraint_violations'])) { // Locate the correct element in the the form. @@ -373,7 +373,7 @@ public function flagErrors(EntityInterface $entity, $langcode, FieldInterface $i } // Reinitialize the errors list for the next submit. $field_state['constraint_violations'] = array(); - field_form_set_state($form['#parents'], $field_name, $langcode, $form_state, $field_state); + field_form_set_state($form['#parents'], $field_name, $form_state, $field_state); } } } diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php index 8e94cc2..a87f9f2 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php @@ -335,15 +335,15 @@ function testFieldAttachForm() { $form_state['form_display'] = entity_get_form_display($entity_type, $this->instance['bundle'], 'default'); field_attach_form($entity, $form, $form_state); - $this->assertEqual($form[$this->field_name]['wrapper']['#title'], $this->instance['label'], "First field's form title is {$this->instance['label']}"); - $this->assertEqual($form[$this->field_name_2]['wrapper']['#title'], $this->instance_2['label'], "Second field's form title is {$this->instance_2['label']}"); + $this->assertEqual($form[$this->field_name]['widget']['#title'], $this->instance['label'], "First field's form title is {$this->instance['label']}"); + $this->assertEqual($form[$this->field_name_2]['widget']['#title'], $this->instance_2['label'], "Second field's form title is {$this->instance_2['label']}"); for ($delta = 0; $delta < $this->field['cardinality']; $delta++) { // field_test_widget uses 'textfield' - $this->assertEqual($form[$this->field_name]['wrapper'][$delta]['value']['#type'], 'textfield', "First field's form delta $delta widget is textfield"); + $this->assertEqual($form[$this->field_name]['widget'][$delta]['value']['#type'], 'textfield', "First field's form delta $delta widget is textfield"); } for ($delta = 0; $delta < $this->field_2['cardinality']; $delta++) { // field_test_widget uses 'textfield' - $this->assertEqual($form[$this->field_name_2]['wrapper'][$delta]['value']['#type'], 'textfield', "Second field's form delta $delta widget is textfield"); + $this->assertEqual($form[$this->field_name_2]['widget'][$delta]['value']['#type'], 'textfield', "Second field's form delta $delta widget is textfield"); } // When generating form for a single field (the second field). @@ -354,10 +354,10 @@ function testFieldAttachForm() { field_attach_form($entity, $form, $form_state, NULL, $options); $this->assertFalse(isset($form[$this->field_name]), 'The first field does not exist in the form'); - $this->assertEqual($form[$this->field_name_2]['wrapper']['#title'], $this->instance_2['label'], "Second field's form title is {$this->instance_2['label']}"); + $this->assertEqual($form[$this->field_name_2]['widget']['#title'], $this->instance_2['label'], "Second field's form title is {$this->instance_2['label']}"); for ($delta = 0; $delta < $this->field_2['cardinality']; $delta++) { // field_test_widget uses 'textfield' - $this->assertEqual($form[$this->field_name_2]['wrapper'][$delta]['value']['#type'], 'textfield', "Second field's form delta $delta widget is textfield"); + $this->assertEqual($form[$this->field_name_2]['widget'][$delta]['value']['#type'], 'textfield', "Second field's form delta $delta widget is textfield"); } } diff --git a/core/modules/field/lib/Drupal/field/Tests/FormTest.php b/core/modules/field/lib/Drupal/field/Tests/FormTest.php index ef378e7..f2f773d 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FormTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FormTest.php @@ -533,7 +533,7 @@ function testFieldFormAccess() { $form_state['form_display'] = entity_get_form_display($entity_type, $entity_type, 'default'); field_attach_form($entity, $form, $form_state); - $this->assertEqual($form[$field_name_no_access]['wrapper'][0]['value']['#entity_type'], $entity_type, 'The correct entity type is set in the field structure.'); + $this->assertEqual($form[$field_name_no_access]['widget'][0]['value']['#entity_type'], $entity_type, 'The correct entity type is set in the field structure.'); $this->assertFalse($form[$field_name_no_access]['#access'], 'Field #access is FALSE for the field without edit access.'); // Display creation form. diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc index a40a44b..09d031d 100644 --- a/core/modules/file/file.field.inc +++ b/core/modules/file/file.field.inc @@ -548,7 +548,6 @@ function file_field_widget_submit($form, &$form_state) { // Go one level up in the form, to the widgets container. $element = NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -1)); $field_name = $element['#field_name']; - $langcode = $element['#language']; $parents = $element['#field_parents']; $submitted_values = NestedArray::getValue($form_state['values'], array_slice($button['#parents'], 0, -2)); @@ -581,9 +580,9 @@ function file_field_widget_submit($form, &$form_state) { NestedArray::setValue($form_state['values'], array_slice($button['#parents'], 0, -2), $submitted_values); // Update items. - $field_state = field_form_get_state($parents, $field_name, $langcode, $form_state); + $field_state = field_form_get_state($parents, $field_name, $form_state); $field_state['items'] = $submitted_values; - field_form_set_state($parents, $field_name, $langcode, $form_state, $field_state); + field_form_set_state($parents, $field_name, $form_state, $field_state); } /** diff --git a/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php b/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php index 1e12c5b..a086d2c 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php +++ b/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php @@ -70,7 +70,7 @@ protected function formMultipleElements(EntityInterface $entity, FieldInterface // Load the items for form rebuilds from the field state as they might not be // in $form_state['values'] because of validation limitations. Also, they are // only passed in as $items when editing existing entities. - $field_state = field_form_get_state($parents, $field_name, $langcode, $form_state); + $field_state = field_form_get_state($parents, $field_name, $form_state); if (isset($field_state['items'])) { $items->setValue($field_state['items']); } diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index f58953d..1d1e06e 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -564,7 +564,7 @@ function forum_form_node_form_alter(&$form, &$form_state, $form_id) { } if (isset($form['taxonomy_forums'])) { - $widget =& $form['taxonomy_forums']['wrapper']; + $widget =& $form['taxonomy_forums']['widget']; // Make the vocabulary required for 'real' forum-nodes. $widget['#required'] = TRUE; $widget['#multiple'] = FALSE; diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php index 11da831..c00cc63 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php @@ -36,9 +36,9 @@ function testUpdateAllowedValues() { // All three options appear. $entity = entity_create('entity_test', array()); $form = \Drupal::entityManager()->getForm($entity); - $this->assertTrue(!empty($form[$this->fieldName]['wrapper'][1]), 'Option 1 exists'); - $this->assertTrue(!empty($form[$this->fieldName]['wrapper'][2]), 'Option 2 exists'); - $this->assertTrue(!empty($form[$this->fieldName]['wrapper'][3]), 'Option 3 exists'); + $this->assertTrue(!empty($form[$this->fieldName]['widget'][1]), 'Option 1 exists'); + $this->assertTrue(!empty($form[$this->fieldName]['widget'][2]), 'Option 2 exists'); + $this->assertTrue(!empty($form[$this->fieldName]['widget'][3]), 'Option 3 exists'); // Use one of the values in an actual entity, and check that this value // cannot be removed from the list. @@ -62,9 +62,9 @@ function testUpdateAllowedValues() { $this->field->save(); $entity = entity_create('entity_test', array()); $form = \Drupal::entityManager()->getForm($entity); - $this->assertTrue(empty($form[$this->fieldName]['wrapper'][1]), 'Option 1 does not exist'); - $this->assertTrue(!empty($form[$this->fieldName]['wrapper'][2]), 'Option 2 exists'); - $this->assertTrue(empty($form[$this->fieldName]['wrapper'][3]), 'Option 3 does not exist'); + $this->assertTrue(empty($form[$this->fieldName]['widget'][1]), 'Option 1 does not exist'); + $this->assertTrue(!empty($form[$this->fieldName]['widget'][2]), 'Option 2 exists'); + $this->assertTrue(empty($form[$this->fieldName]['widget'][3]), 'Option 3 does not exist'); // Completely new options appear. $this->field->settings['allowed_values'] = array(10 => 'Update', 20 => 'Twenty'); @@ -73,11 +73,11 @@ function testUpdateAllowedValues() { // setting, so we need to reintialize the entity object. $entity = entity_create('entity_test', array()); $form = \Drupal::entityManager()->getForm($entity); - $this->assertTrue(empty($form[$this->fieldName]['wrapper'][1]), 'Option 1 does not exist'); - $this->assertTrue(empty($form[$this->fieldName]['wrapper'][2]), 'Option 2 does not exist'); - $this->assertTrue(empty($form[$this->fieldName]['wrapper'][3]), 'Option 3 does not exist'); - $this->assertTrue(!empty($form[$this->fieldName]['wrapper'][10]), 'Option 10 exists'); - $this->assertTrue(!empty($form[$this->fieldName]['wrapper'][20]), 'Option 20 exists'); + $this->assertTrue(empty($form[$this->fieldName]['widget'][1]), 'Option 1 does not exist'); + $this->assertTrue(empty($form[$this->fieldName]['widget'][2]), 'Option 2 does not exist'); + $this->assertTrue(empty($form[$this->fieldName]['widget'][3]), 'Option 3 does not exist'); + $this->assertTrue(!empty($form[$this->fieldName]['widget'][10]), 'Option 10 exists'); + $this->assertTrue(!empty($form[$this->fieldName]['widget'][20]), 'Option 20 exists'); // Options are reset when a new field with the same name is created. $this->field->delete(); @@ -94,8 +94,8 @@ function testUpdateAllowedValues() { ->save(); $entity = entity_create('entity_test', array()); $form = \Drupal::entityManager()->getForm($entity); - $this->assertTrue(!empty($form[$this->fieldName]['wrapper'][1]), 'Option 1 exists'); - $this->assertTrue(!empty($form[$this->fieldName]['wrapper'][2]), 'Option 2 exists'); - $this->assertTrue(!empty($form[$this->fieldName]['wrapper'][3]), 'Option 3 exists'); + $this->assertTrue(!empty($form[$this->fieldName]['widget'][1]), 'Option 1 exists'); + $this->assertTrue(!empty($form[$this->fieldName]['widget'][2]), 'Option 2 exists'); + $this->assertTrue(!empty($form[$this->fieldName]['widget'][3]), 'Option 3 exists'); } }