annotate core/modules/taxonomy/src/TermTranslationHandler.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\taxonomy;
Chris@0 4
Chris@0 5 use Drupal\Core\Entity\EntityInterface;
Chris@0 6 use Drupal\content_translation\ContentTranslationHandler;
Chris@0 7 use Drupal\Core\Form\FormStateInterface;
Chris@0 8
Chris@0 9 /**
Chris@0 10 * Defines the translation handler for terms.
Chris@0 11 */
Chris@0 12 class TermTranslationHandler extends ContentTranslationHandler {
Chris@0 13
Chris@0 14 /**
Chris@0 15 * {@inheritdoc}
Chris@0 16 */
Chris@0 17 public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
Chris@0 18 parent::entityFormAlter($form, $form_state, $entity);
Chris@0 19 $form['actions']['submit']['#submit'][] = [$this, 'entityFormSave'];
Chris@0 20 }
Chris@0 21
Chris@0 22 /**
Chris@0 23 * Form submission handler for TermTranslationHandler::entityFormAlter().
Chris@0 24 *
Chris@0 25 * This handles the save action.
Chris@0 26 *
Chris@0 27 * @see \Drupal\Core\Entity\EntityForm::build()
Chris@0 28 */
Chris@0 29 public function entityFormSave(array $form, FormStateInterface $form_state) {
Chris@0 30 if ($this->getSourceLangcode($form_state)) {
Chris@0 31 $entity = $form_state->getFormObject()->getEntity();
Chris@0 32 // We need a redirect here, otherwise we would get an access denied page,
Chris@0 33 // since the current URL would be preserved and we would try to add a
Chris@0 34 // translation for a language that already has a translation.
Chris@18 35 $form_state->setRedirectUrl($entity->toUrl('edit-form'));
Chris@0 36 }
Chris@0 37 }
Chris@0 38
Chris@0 39 }