Backup of db before drupal security update
[yaffs-website] / web / core / modules / user / src / ProfileTranslationHandler.php
1 <?php
2
3 namespace Drupal\user;
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 users.
11  */
12 class ProfileTranslationHandler extends ContentTranslationHandler {
13
14   /**
15    * {@inheritdoc}
16    */
17   protected function hasPublishedStatus() {
18     // User status has nothing to do with translations visibility.
19     return FALSE;
20   }
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function hasCreatedTime() {
26     // User creation date has nothing to do with translation creation date.
27     return FALSE;
28   }
29
30   /**
31    * {@inheritdoc}
32    */
33   public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
34     parent::entityFormAlter($form, $form_state, $entity);
35     $form['actions']['submit']['#submit'][] = [$this, 'entityFormSave'];
36   }
37
38   /**
39    * Form submission handler for ProfileTranslationHandler::entityFormAlter().
40    *
41    * This handles the save action.
42    *
43    * @see \Drupal\Core\Entity\EntityForm::build()
44    */
45   public function entityFormSave(array $form, FormStateInterface $form_state) {
46     if ($this->getSourceLangcode($form_state)) {
47       $entity = $form_state->getFormObject()->getEntity();
48       // We need a redirect here, otherwise we would get an access denied page
49       // since the current URL would be preserved and we would try to add a
50       // translation for a language that already has a translation.
51       $form_state->setRedirectUrl($entity->urlInfo());
52     }
53   }
54
55 }