class ProfileTranslationHandler
Same name and namespace in other branches
- 11.x core/modules/user/src/ProfileTranslationHandler.php \Drupal\user\ProfileTranslationHandler
- 10 core/modules/user/src/ProfileTranslationHandler.php \Drupal\user\ProfileTranslationHandler
- 8.9.x core/modules/user/src/ProfileTranslationHandler.php \Drupal\user\ProfileTranslationHandler
Defines the translation handler for users.
Hierarchy
- class \Drupal\content_translation\ContentTranslationHandler implements \Drupal\content_translation\ContentTranslationHandlerInterface, \Drupal\Core\Entity\EntityHandlerInterface uses \Drupal\Core\Entity\EntityChangesDetectionTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait
- class \Drupal\user\ProfileTranslationHandler extends \Drupal\content_translation\ContentTranslationHandler
Expanded class hierarchy of ProfileTranslationHandler
File
-
core/
modules/ user/ src/ ProfileTranslationHandler.php, line 12
Namespace
Drupal\userView source
class ProfileTranslationHandler extends ContentTranslationHandler {
/**
* {@inheritdoc}
*/
protected function hasPublishedStatus() {
// User status has nothing to do with translations visibility.
return FALSE;
}
/**
* {@inheritdoc}
*/
protected function hasCreatedTime() {
// User creation date has nothing to do with translation creation date.
return FALSE;
}
/**
* {@inheritdoc}
*/
public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
parent::entityFormAlter($form, $form_state, $entity);
$form['actions']['submit']['#submit'][] = [
$this,
'entityFormSave',
];
}
/**
* Form submission handler for ProfileTranslationHandler::entityFormAlter().
*
* This handles the save action.
*
* @see \Drupal\Core\Entity\EntityForm::build()
*/
public function entityFormSave(array $form, FormStateInterface $form_state) {
if ($this->getSourceLangcode($form_state)) {
$entity = $form_state->getFormObject()
->getEntity();
// We need a redirect here, otherwise we would get an access denied page
// since the current URL would be preserved and we would try to add a
// translation for a language that already has a translation.
$form_state->setRedirectUrl($entity->toUrl());
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.