Backup of db before drupal security update
[yaffs-website] / web / core / modules / taxonomy / src / TermTranslationHandler.php
1 <?php
2
3 namespace Drupal\taxonomy;
4
5 use Drupal\Core\Entity\EntityInterface;
6 use Drupal\content_translation\ContentTranslationHandler;
7 use Drupal\Core\Form\FormStateInterface;
8
9 /**
10  * Defines the translation handler for terms.
11  */
12 class TermTranslationHandler extends ContentTranslationHandler {
13
14   /**
15    * {@inheritdoc}
16    */
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'];
20   }
21
22   /**
23    * Form submission handler for TermTranslationHandler::entityFormAlter().
24    *
25    * This handles the save action.
26    *
27    * @see \Drupal\Core\Entity\EntityForm::build()
28    */
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'));
36     }
37   }
38
39 }