3 namespace Drupal\taxonomy;
5 use Drupal\Core\Entity\EntityInterface;
6 use Drupal\content_translation\ContentTranslationHandler;
7 use Drupal\Core\Form\FormStateInterface;
10 * Defines the translation handler for terms.
12 class TermTranslationHandler extends ContentTranslationHandler {
17 public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
18 parent::entityFormAlter($form, $form_state, $entity);
19 $form['actions']['submit']['#submit'][] = [$this, 'entityFormSave'];
23 * Form submission handler for TermTranslationHandler::entityFormAlter().
25 * This handles the save action.
27 * @see \Drupal\Core\Entity\EntityForm::build()
29 public function entityFormSave(array $form, FormStateInterface $form_state) {
30 if ($this->getSourceLangcode($form_state)) {
31 $entity = $form_state->getFormObject()->getEntity();
32 // We need a redirect here, otherwise we would get an access denied page,
33 // since the current URL would be preserved and we would try to add a
34 // translation for a language that already has a translation.
35 $form_state->setRedirectUrl($entity->urlInfo('edit-form'));