function ContentTranslationHandler::entityFormSourceChange

Same name in other branches
  1. 9 core/modules/content_translation/src/ContentTranslationHandler.php \Drupal\content_translation\ContentTranslationHandler::entityFormSourceChange()
  2. 8.9.x core/modules/content_translation/src/ContentTranslationHandler.php \Drupal\content_translation\ContentTranslationHandler::entityFormSourceChange()
  3. 10 core/modules/content_translation/src/ContentTranslationHandler.php \Drupal\content_translation\ContentTranslationHandler::entityFormSourceChange()

Form submission handler for ContentTranslationHandler::entityFormAlter().

Takes care of the source language change.

File

core/modules/content_translation/src/ContentTranslationHandler.php, line 720

Class

ContentTranslationHandler
Base class for content translation handlers.

Namespace

Drupal\content_translation

Code

public function entityFormSourceChange($form, FormStateInterface $form_state) {
    $form_object = $form_state->getFormObject();
    $entity = $form_object->getEntity();
    $source = $form_state->getValue([
        'source_langcode',
        'source',
    ]);
    $entity_type_id = $entity->getEntityTypeId();
    $form_state->setRedirect("entity.{$entity_type_id}.content_translation_add", [
        $entity_type_id => $entity->id(),
        'source' => $source,
        'target' => $form_object->getFormLangcode($form_state),
    ]);
    $languages = $this->languageManager
        ->getLanguages();
    $this->messenger
        ->addStatus($this->t('Source language set to: %language', [
        '%language' => $languages[$source]->getName(),
    ]));
}

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