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