diff --git a/core/lib/Drupal/Core/Entity/ContentEntityForm.php b/core/lib/Drupal/Core/Entity/ContentEntityForm.php index 6980701..c892401 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityForm.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityForm.php @@ -50,6 +50,11 @@ public static function create(ContainerInterface $container) { */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); + + // Content entity forms are doing their own entity building so there's no + // need to use the parent one. + unset($form['#after_build']); + $this->getFormDisplay($form_state)->buildForm($this->entity, $form, $form_state); // Allow modules to act before and after form language is updated. $form['#entity_builders']['update_form_langcode'] = [$this, 'updateFormLangcode']; @@ -69,7 +74,7 @@ public function form(array $form, FormStateInterface $form_state) { * https://www.drupal.org/node/2015613. */ public function validate(array $form, FormStateInterface $form_state) { - $entity = $this->entity; + $entity = $this->buildEntity($form, $form_state); $this->getFormDisplay($form_state)->validateFormValues($entity, $form, $form_state); // @todo Remove this. @@ -80,6 +85,17 @@ public function validate(array $form, FormStateInterface $form_state) { } /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + parent::submitForm($form, $form_state); + + // Remove button and internal Form API values from submitted values. + $form_state->cleanValues(); + $this->entity = $this->buildEntity($form, $form_state); + } + + /** * Initializes the form state and the entity before the first form build. * * @param \Drupal\Core\Form\FormStateInterface $form_state diff --git a/core/lib/Drupal/Core/Field/WidgetBase.php b/core/lib/Drupal/Core/Field/WidgetBase.php index 73fb556..ef64fea 100644 --- a/core/lib/Drupal/Core/Field/WidgetBase.php +++ b/core/lib/Drupal/Core/Field/WidgetBase.php @@ -341,11 +341,7 @@ public function extractFormValues(FieldItemListInterface $items, array $form, Fo // Extract the values from $form_state->getValues(). $path = array_merge($form['#parents'], array($field_name)); $key_exists = NULL; - - // Make sure that the massageFormValues() call below always receives an - // array as the first argument because some widgets might not impose this - // structure on its elements (e.g. the 'options_select' widget). - $values = (array) NestedArray::getValue($form_state->getValues(), $path, $key_exists); + $values = NestedArray::getValue($form_state->getValues(), $path, $key_exists); if ($key_exists) { // Account for drag-and-drop reordering if needed.