5 use Drupal\Core\Entity\EntityInterface;
6 use Drupal\content_translation\ContentTranslationHandler;
7 use Drupal\Core\Form\FormStateInterface;
10 * Defines the translation handler for users.
12 class ProfileTranslationHandler extends ContentTranslationHandler {
17 protected function hasPublishedStatus() {
18 // User status has nothing to do with translations visibility.
25 protected function hasCreatedTime() {
26 // User creation date has nothing to do with translation creation date.
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'];
39 * Form submission handler for ProfileTranslationHandler::entityFormAlter().
41 * This handles the save action.
43 * @see \Drupal\Core\Entity\EntityForm::build()
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());