public function ContentEntityForm::updateFormLangcode in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Entity/ContentEntityForm.php \Drupal\Core\Entity\ContentEntityForm::updateFormLangcode()
- 9 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\EntityCode
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);
}
}