W3cubDocs

/Drupal 8

protected function ContentEntityForm::initFormLangcodes

protected ContentEntityForm::initFormLangcodes(FormStateInterface $form_state)

Initializes form language code values.

Parameters

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

File

core/lib/Drupal/Core/Entity/ContentEntityForm.php, line 185

Class

ContentEntityForm
Entity form variant for content entity types.

Namespace

Drupal\Core\Entity

Code

protected function initFormLangcodes(FormStateInterface $form_state) {
  // Store the entity default language to allow checking whether the form is
  // dealing with the original entity or a translation.
  if (!$form_state->has('entity_default_langcode')) {
    $form_state->set('entity_default_langcode', $this->entity->getUntranslated()->language()->getId());
  }
  // This value might have been explicitly populated to work with a particular
  // entity translation. If not we fall back to the most proper language based
  // on contextual information.
  if (!$form_state->has('langcode')) {
    // Imply a 'view' operation to ensure users edit entities in the same
    // language they are displayed. This allows to keep contextual editing
    // working also for multilingual entities.
    $form_state->set('langcode', $this->entityManager->getTranslationFromContext($this->entity)->language()->getId());
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!ContentEntityForm.php/function/ContentEntityForm::initFormLangcodes/8.1.x