diff --git a/core/lib/Drupal/Core/Entity/EntityFormController.php b/core/lib/Drupal/Core/Entity/EntityFormController.php index 07dd8f3..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); @@ -339,7 +338,6 @@ public function submit(array $form, array &$form_state) { form_state_values_clean($form_state); $this->updateFormLangcode($form_state); - $this->submitEntityLanguage($form, $form_state); $this->entity = $this->buildEntity($form, $form_state); return $this->entity; } @@ -415,42 +413,6 @@ protected function updateFormLangcode(array &$form_state) { } /** - * Handle possible entity language changes. - * - * @param array $form - * An associative array containing the structure of the form. - * @param array $form_state - * A reference to a keyed array containing the current state of the form. - */ - protected function submitEntityLanguage(array $form, array &$form_state) { - $entity = $this->entity; - $entity_type = $entity->entityType(); - - if (field_has_translation_handler($entity_type)) { - // If we are editing the default language values, we use the submitted - // entity language as the new language for fields to handle any language - // change. Otherwise the current form language is the proper value, since - // in this case it is not supposed to change. - $current_langcode = $this->isDefaultFormLangcode($form_state) ? $form_state['values']['langcode'] : $this->getFormLangcode($form_state); - - foreach (field_info_instances($entity_type, $entity->bundle()) as $instance) { - $field = $instance->getField(); - $field_name = $field->name; - if (isset($form[$field_name]['#language'])) { - $previous_langcode = $form[$field_name]['#language']; - - // Handle a possible language change: new language values are inserted, - // previous ones are deleted. - if ($field['translatable'] && $previous_langcode != $current_langcode) { - $form_state['values'][$field_name][$current_langcode] = $form_state['values'][$field_name][$previous_langcode]; - $form_state['values'][$field_name][$previous_langcode] = array(); - } - } - } - } - } - - /** * Implements \Drupal\Core\Entity\EntityFormControllerInterface::buildEntity(). */ public function buildEntity(array $form, array &$form_state) { diff --git a/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php b/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php index f760057..11396d9 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php +++ b/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php @@ -38,16 +38,6 @@ public function form(array $form, array &$form_state) { } /** - * Overrides EntityFormController::submitEntityLanguage(). - */ - protected function submitEntityLanguage(array $form, array &$form_state) { - // Nothing to do here, as original field values are always stored with - // Language::LANGCODE_DEFAULT language. - // @todo Delete this method when merging EntityFormControllerNG with - // EntityFormController. - } - - /** * Overrides EntityFormController::buildEntity(). */ public function buildEntity(array $form, array &$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 6faa0c9..1477e46 100644 --- a/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php +++ b/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php @@ -133,9 +133,7 @@ protected function buildEntity(array $form, array &$form_state) { */ protected function simplify(array &$form, array &$form_state) { $field_name = $form_state['field_name']; - $langcode = $form_state['langcode']; - - $widget_element =& $form[$field_name][$langcode]; + $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 25677ac..8ac601e 100644 --- a/core/modules/field/field.deprecated.inc +++ b/core/modules/field/field.deprecated.inc @@ -483,15 +483,10 @@ function field_read_instances($conditions = array(), $include_additional = array * // most common case), and will therefore be repeated as many times as * // needed, or 'multiple-values' (one single widget allows the input of * // several values, e.g checkboxes, select box...). - * // The sub-array is nested into a $langcode key where $langcode has the - * // same value of the $langcode parameter above. - * // The '#language' key holds the same value of $langcode and it is used - * // to access the field sub-array when $langcode is unknown. * 'field_foo' => array( - * '#tree' => TRUE, - * '#field_name' => The name of the field, - * '#language' => $langcode, - * $langcode => array( + * '#access' => TRUE if the current user has 'edit' grants for the field, + * FALSE if not. + * 'widget' => array( * '#field_name' => The name of the field, * '#language' => $langcode, * '#field_parents' => The 'parents' space for the field in the form, @@ -634,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 4cf4556..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 @@ -58,21 +58,16 @@ public function __construct($plugin_id, array $plugin_definition, FieldDefinitio */ public function form(EntityInterface $entity, $langcode, FieldInterface $items, array &$form, array &$form_state, $get_delta = NULL) { $field_name = $this->fieldDefinition->getFieldName(); - $parents = $form['#parents']; - $addition = array( - $field_name => array(), - ); - // 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,37 +105,38 @@ public function form(EntityInterface $entity, $langcode, FieldInterface $items, $elements = $this->formMultipleElements($entity, $items, $langcode, $form, $form_state); } - // Also aid in theming of field widgets by rendering a classified - // container. - $addition[$field_name] = array( - '#type' => 'container', - '#attributes' => array( - 'class' => array( - 'field-type-' . drupal_html_class($this->fieldDefinition->getFieldType()), - 'field-name-' . drupal_html_class($field_name), - 'field-widget-' . drupal_html_class($this->getPluginId()), - ), - ), - ); - // Populate the 'array_parents' information in $form_state['field'] after // the form is built, so that we catch changes in the form structure performed // 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; - - $addition[$field_name] += array( - '#tree' => TRUE, - // The '#language' key can be used to access the field's form element - // when $langcode is unknown. - '#language' => $langcode, - $langcode => $elements, - '#access' => $this->checkFieldAccess('edit', $entity), + // Enforce the structure of submitted values. + $elements['#parents'] = array_merge($parents, array($field_name)); + // Most widgets need their internal structure preserved in submitted values. + $elements += array('#tree' => TRUE); + + $return = array( + $field_name => array( + // Aid in theming of widgets by rendering a classified container. + '#type' => 'container', + // Assign a different parent, to keep the main id for the widget itself. + '#parents' => array_merge($parents, array($field_name . '_wrapper')), + '#attributes' => array( + 'class' => array( + 'field-type-' . drupal_html_class($this->fieldDefinition->getFieldType()), + 'field-name-' . drupal_html_class($field_name), + 'field-widget-' . drupal_html_class($this->getPluginId()), + ), + ), + '#access' => $this->checkFieldAccess('edit', $entity), + 'widget' => $elements, + ), ); - return $addition; + return $return; } /** @@ -159,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; @@ -285,7 +281,7 @@ public function extractFormValues(EntityInterface $entity, $langcode, FieldInter $field_name = $this->fieldDefinition->getFieldName(); // Extract the values from $form_state['values']. - $path = array_merge($form['#parents'], array($field_name, $langcode)); + $path = array_merge($form['#parents'], array($field_name)); $key_exists = NULL; $values = NestedArray::getValue($form_state['values'], $path, $key_exists); @@ -322,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); } } @@ -337,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. @@ -377,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/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 0f076c4..1d1e06e 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -263,7 +263,6 @@ function forum_uri($forum) { */ function forum_node_validate(EntityInterface $node, $form) { if (Drupal::service('forum_manager')->checkNodeType($node)) { - $langcode = $form['taxonomy_forums']['#language']; // vocabulary is selected, not a "container" term. if (!$node->taxonomy_forums->isEmpty()) { // Extract the node's proper topic ID. @@ -565,16 +564,16 @@ function forum_form_node_form_alter(&$form, &$form_state, $form_id) { } if (isset($form['taxonomy_forums'])) { - $langcode = $form['taxonomy_forums']['#language']; + $widget =& $form['taxonomy_forums']['widget']; // Make the vocabulary required for 'real' forum-nodes. - $form['taxonomy_forums'][$langcode]['#required'] = TRUE; - $form['taxonomy_forums'][$langcode]['#multiple'] = FALSE; - if (empty($form['taxonomy_forums'][$langcode]['#default_value'])) { + $widget['#required'] = TRUE; + $widget['#multiple'] = FALSE; + if (empty($widget['#default_value'])) { // If there is no default forum already selected, try to get the forum // ID from the URL (e.g., if we are on a page like node/add/forum/2, we // expect "2" to be the ID of the forum that was requested). $requested_forum_id = arg(3); - $form['taxonomy_forums'][$langcode]['#default_value'] = is_numeric($requested_forum_id) ? $requested_forum_id : ''; + $widget['#default_value'] = is_numeric($requested_forum_id) ? $requested_forum_id : ''; } } }