You are here

protected function ContentEntityForm::initFormLangcodes in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Entity/ContentEntityForm.php \Drupal\Core\Entity\ContentEntityForm::initFormLangcodes()

Initializes form language code values.

Parameters

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

3 calls to ContentEntityForm::initFormLangcodes()
ContentEntityForm::getFormLangcode in core/lib/Drupal/Core/Entity/ContentEntityForm.php
Gets the code identifying the active form language.
ContentEntityForm::init in core/lib/Drupal/Core/Entity/ContentEntityForm.php
Initializes the form state and the entity before the first form build.
ContentEntityForm::isDefaultFormLangcode in core/lib/Drupal/Core/Entity/ContentEntityForm.php
Checks whether the current form language matches the entity one.

File

core/lib/Drupal/Core/Entity/ContentEntityForm.php, line 190
Contains \Drupal\Core\Entity\ContentEntityForm.

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());
  }
}