getSourceLangcode example

$form['actions']['submit']['#submit'][] = [$this, 'entityFormSave'];
  }

  /** * Form submission handler for ProfileTranslationHandler::entityFormAlter(). * * This handles the save action. * * @see \Drupal\Core\Entity\EntityForm::build() */
  public function entityFormSave(array $form, FormStateInterface $form_state) {
    if ($this->getSourceLangcode($form_state)) {
      $entity = $form_state->getFormObject()->getEntity();
      // We need a redirect here, otherwise we would get an access denied page       // since the current URL would be preserved and we would try to add a       // translation for a language that already has a translation.       $form_state->setRedirectUrl($entity->toUrl());
    }
  }

}
$form['actions']['submit']['#submit'][] = [$this, 'entityFormSave'];
  }

  /** * Form submission handler for TermTranslationHandler::entityFormAlter(). * * This handles the save action. * * @see \Drupal\Core\Entity\EntityForm::build() */
  public function entityFormSave(array $form, FormStateInterface $form_state) {
    if ($this->getSourceLangcode($form_state)) {
      $entity = $form_state->getFormObject()->getEntity();
      // We need a redirect here, otherwise we would get an access denied page,       // since the current URL would be preserved and we would try to add a       // translation for a language that already has a translation.       $form_state->setRedirectUrl($entity->toUrl('edit-form'));
    }
  }

  /** * {@inheritdoc} */
  
Home | Imprint | This part of the site doesn't use cookies.