W3cubDocs

/Drupal 8

public function ContentEntityForm::updateFormLangcode

public ContentEntityForm::updateFormLangcode($entity_type_id, EntityInterface $entity, array $form, FormStateInterface $form_state)

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 268

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

© 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::updateFormLangcode/8.1.x