function ContentEntityForm::updateFormLangcode

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/ContentEntityForm.php \Drupal\Core\Entity\ContentEntityForm::updateFormLangcode()
  2. 8.9.x core/lib/Drupal/Core/Entity/ContentEntityForm.php \Drupal\Core\Entity\ContentEntityForm::updateFormLangcode()
  3. 10 core/lib/Drupal/Core/Entity/ContentEntityForm.php \Drupal\Core\Entity\ContentEntityForm::updateFormLangcode()

Updates the form language to reflect any change to the entity language.

There are use cases for modules to act both before and after form language being updated, thus the update is performed through an entity builder callback, which allows to support both cases.

Parameters

string $entity_type_id: The entity type identifier.

\Drupal\Core\Entity\EntityInterface $entity: The entity updated with the submitted values.

array $form: The complete form array.

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

See also

\Drupal\Core\Entity\ContentEntityForm::form()

File

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

Class

ContentEntityForm
Entity form variant for content entity types.

Namespace

Drupal\Core\Entity

Code

public function updateFormLangcode($entity_type_id, EntityInterface $entity, array $form, FormStateInterface $form_state) {
    $langcode = $entity->language()
        ->getId();
    $form_state->set('langcode', $langcode);
    // If this is the original entity language, also update the default
    // langcode.
    if ($langcode == $entity->getUntranslated()
        ->language()
        ->getId()) {
        $form_state->set('entity_default_langcode', $langcode);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.