You are here

public function ContentEntityForm::updateFormLangcode 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::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 273
Contains \Drupal\Core\Entity\ContentEntityForm.

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) {

  // Update the form language as it might have changed.
  if ($this
    ->isDefaultFormLangcode($form_state)) {
    $langcode = $entity
      ->language()
      ->getId();
    $form_state
      ->set('langcode', $langcode);
  }
}