diff --git a/core/lib/Drupal/Core/Entity/ContentEntityFormController.php b/core/lib/Drupal/Core/Entity/ContentEntityFormController.php index de83f56..31076aa 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityFormController.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityFormController.php @@ -15,7 +15,7 @@ * * @see \Drupal\Core\ContentEntityBase */ -class ContentEntityFormController extends EntityFormController { +class ContentEntityFormController extends EntityFormController implements ContentEntityFormControllerInterface { /** * The entity manager. @@ -160,4 +160,18 @@ public function buildEntity(array $form, array &$form_state) { return $entity; } + /** + * Updates the form language to reflect any change to the entity language. + * + * @param array $form_state + * A reference to a keyed array containing the current state of the form. + */ + protected function updateFormLangcode(array &$form_state) { + // Update the form language as it might have changed. + if (isset($form_state['values']['langcode']) && $this->isDefaultFormLangcode($form_state)) { + $form_state['langcode'] = $form_state['values']['langcode']; + } + } + + } diff --git a/core/lib/Drupal/Core/Entity/ContentEntityFormControllerInterface.php b/core/lib/Drupal/Core/Entity/ContentEntityFormControllerInterface.php new file mode 100644 index 0000000..d8d728b --- /dev/null +++ b/core/lib/Drupal/Core/Entity/ContentEntityFormControllerInterface.php @@ -0,0 +1,37 @@ +entityInfo()->isFieldable()) { - field_attach_form($entity, $form, $form_state, $this->getFormLangcode($form_state)); + field_attach_form($entity, $form, $form_state); } // Add a process callback so we can assign weights and hide extra fields. $form['#process'][] = array($this, '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; } @@ -260,7 +251,6 @@ protected function actions(array $form, array &$form_state) { * {@inheritdoc} */ public function validate(array $form, array &$form_state) { - $this->updateFormLangcode($form_state); // @todo Remove this. // Execute legacy global validation handlers. unset($form_state['validate_handlers']); @@ -315,34 +305,6 @@ public function delete(array $form, array &$form_state) { /** * {@inheritdoc} */ - public function getFormLangcode(array &$form_state) { - return $this->entity->language()->id; - } - - /** - * {@inheritdoc} - */ - public function isDefaultFormLangcode(array $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 array $form_state - * A reference to a keyed array containing the current state of the form. - */ - protected function updateFormLangcode(array &$form_state) { - // Update the form language as it might have changed. - if (isset($form_state['values']['langcode']) && $this->isDefaultFormLangcode($form_state)) { - $form_state['langcode'] = $form_state['values']['langcode']; - } - } - - /** - * {@inheritdoc} - */ public function buildEntity(array $form, array &$form_state) { $entity = clone $this->entity; // If you submit a form, the form state comes from caching, which forces diff --git a/core/lib/Drupal/Core/Entity/EntityFormControllerInterface.php b/core/lib/Drupal/Core/Entity/EntityFormControllerInterface.php index e63679b..97de9cf 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormControllerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityFormControllerInterface.php @@ -18,28 +18,6 @@ interface EntityFormControllerInterface extends BaseFormIdInterface { /** - * Returns the code identifying the active form language. - * - * @param array $form_state - * An associative array containing the current state of the form. - * - * @return string - * The form language code. - */ - public function getFormLangcode(array &$form_state); - - /** - * Checks whether the current form language matches the entity one. - * - * @param array $form_state - * A keyed array containing the current state of the form. - * - * @return boolean - * Returns TRUE if the entity form language matches the entity one. - */ - public function isDefaultFormLangcode(array $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 a6f7987..8ccbab6 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -7,11 +7,10 @@ use Drupal\content_translation\Plugin\Derivative\ContentTranslationLocalTasks; use Drupal\Core\Entity\ContentEntityInterface; -use Drupal\Core\Entity\EntityFormControllerInterface; +use Drupal\Core\Entity\ContentEntityFormControllerInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Language\Language; use Drupal\Core\Session\AccountInterface; -use Drupal\Core\TypedData\TranslatableInterface; use Drupal\node\NodeInterface; /** @@ -554,7 +553,7 @@ function content_translation_controller($entity_type) { * @todo Move to \Drupal\content_translation\ContentTranslationManager. */ function content_translation_form_controller(array $form_state) { - return isset($form_state['controller']) && $form_state['controller'] instanceof EntityFormControllerInterface ? $form_state['controller'] : FALSE; + return isset($form_state['controller']) && $form_state['controller'] instanceof ContentEntityFormControllerInterface ? $form_state['controller'] : FALSE; } /**