diff --git a/core/lib/Drupal/Core/Entity/ContentEntityForm.php b/core/lib/Drupal/Core/Entity/ContentEntityForm.php index f1a10ca..64374cf 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityForm.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityForm.php @@ -135,4 +135,17 @@ public function setFormDisplay(EntityFormDisplayInterface $form_display, FormSta return $this; } + /** + * Updates the form language to reflect any change to the entity language. + * + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The current state of the form. + */ + protected function updateFormLangcode(FormStateInterface $form_state) { + // Update the form language as it might have changed. + if ($form_state->hasValue('langcode') && $this->isDefaultFormLangcode($form_state)) { + $form_state->set('langcode', $form_state->getValue('langcode')); + } + } + } diff --git a/core/lib/Drupal/Core/Entity/ContentEntityFormInterface.php b/core/lib/Drupal/Core/Entity/ContentEntityFormInterface.php index 4d5cf4d..4f130dc 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityFormInterface.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityFormInterface.php @@ -39,4 +39,26 @@ public function getFormDisplay(FormStateInterface $form_state); */ public function setFormDisplay(EntityFormDisplayInterface $form_display, FormStateInterface $form_state); + /** + * Returns the code identifying the active form language. + * + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The current state of the form. + * + * @return string + * The form language code. + */ + public function getFormLangcode(FormStateInterface $form_state); + + /** + * Checks whether the current form language matches the entity one. + * + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The current state of the form. + * + * @return boolean + * Returns TRUE if the entity form language matches the entity one. + */ + public function isDefaultFormLangcode(FormStateInterface $form_state); + } diff --git a/core/lib/Drupal/Core/Entity/EntityForm.php b/core/lib/Drupal/Core/Entity/EntityForm.php index 407b9d7..0a46a2e 100644 --- a/core/lib/Drupal/Core/Entity/EntityForm.php +++ b/core/lib/Drupal/Core/Entity/EntityForm.php @@ -131,15 +131,6 @@ public function form(array $form, FormStateInterface $form_state) { // Add a process callback. $form['#process'][] = '::processForm'; - if (!isset($form['langcode'])) { - // If the form did not specify otherwise, default to keeping the existing - // language of the entity or defaulting to the site default language for - // new entities. - $form['langcode'] = array( - '#type' => 'value', - '#value' => !$entity->isNew() ? $entity->language()->id : language_default()->id, - ); - } return $form; } @@ -232,7 +223,6 @@ protected function actions(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function validate(array $form, FormStateInterface $form_state) { - $this->updateFormLangcode($form_state); // @todo Remove this. // Execute legacy global validation handlers. $form_state->setValidateHandlers([]); @@ -272,34 +262,6 @@ public function save(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function getFormLangcode(FormStateInterface $form_state) { - return $this->entity->language()->id; - } - - /** - * {@inheritdoc} - */ - public function isDefaultFormLangcode(FormStateInterface $form_state) { - // The entity is not translatable, this is always the default language. - return TRUE; - } - - /** - * Updates the form language to reflect any change to the entity language. - * - * @param \Drupal\Core\Form\FormStateInterface $form_state - * The current state of the form. - */ - protected function updateFormLangcode(FormStateInterface $form_state) { - // Update the form language as it might have changed. - if ($form_state->hasValue('langcode') && $this->isDefaultFormLangcode($form_state)) { - $form_state->set('langcode', $form_state->getValue('langcode')); - } - } - - /** - * {@inheritdoc} - */ public function buildEntity(array $form, FormStateInterface $form_state) { $entity = clone $this->entity; $this->copyFormValuesToEntity($entity, $form, $form_state); diff --git a/core/lib/Drupal/Core/Entity/EntityFormInterface.php b/core/lib/Drupal/Core/Entity/EntityFormInterface.php index 2d63284..b8ecab1 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityFormInterface.php @@ -18,28 +18,6 @@ interface EntityFormInterface extends BaseFormIdInterface { /** - * Returns the code identifying the active form language. - * - * @param \Drupal\Core\Form\FormStateInterface $form_state - * The current state of the form. - * - * @return string - * The form language code. - */ - public function getFormLangcode(FormStateInterface $form_state); - - /** - * Checks whether the current form language matches the entity one. - * - * @param \Drupal\Core\Form\FormStateInterface $form_state - * The current state of the form. - * - * @return boolean - * Returns TRUE if the entity form language matches the entity one. - */ - public function isDefaultFormLangcode(FormStateInterface $form_state); - - /** * Sets the operation for this form. * * @param string $operation diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 49e4b67..102c67a 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -7,7 +7,7 @@ use Drupal\Core\Access\AccessResult; use Drupal\Core\Entity\ContentEntityInterface; -use Drupal\Core\Entity\EntityFormInterface; +use Drupal\Core\Entity\ContentEntityFormInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; @@ -364,7 +364,7 @@ function content_translation_access(EntityInterface $entity, $op) { */ function content_translation_form_alter(array &$form, FormStateInterface $form_state) { $form_object = $form_state->getFormObject(); - if (!($form_object instanceof EntityFormInterface)) { + if (!($form_object instanceof ContentEntityFormInterface)) { return; } $entity = $form_object->getEntity();