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);
  }
}
doc_Drupal
2016-10-29 08:57:17
Comments
Leave a Comment

Please login to continue.