Mercurial > hg > isophonics-drupal-site
diff core/modules/taxonomy/src/TermTranslationHandler.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | af1871eacc83 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/modules/taxonomy/src/TermTranslationHandler.php Wed Nov 29 16:09:58 2017 +0000 @@ -0,0 +1,39 @@ +<?php + +namespace Drupal\taxonomy; + +use Drupal\Core\Entity\EntityInterface; +use Drupal\content_translation\ContentTranslationHandler; +use Drupal\Core\Form\FormStateInterface; + +/** + * Defines the translation handler for terms. + */ +class TermTranslationHandler extends ContentTranslationHandler { + + /** + * {@inheritdoc} + */ + public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) { + parent::entityFormAlter($form, $form_state, $entity); + $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->urlInfo('edit-form')); + } + } + +}