diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 5f6fb13..323edb5 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -402,8 +402,11 @@ function content_translation_view_access(EntityInterface $entity, $langcode, Acc if (!empty($info['permission_granularity']) && $info['permission_granularity'] == 'bundle') { $permission = "translate {$entity->bundle()} $entity_type"; } + if (!isset($account)) { + $account = \Drupal::currentUser(); + } $status = $entity instanceof ContentEntityInterface ? !empty($entity->getTranslation($langcode)->translation_status->value) : FALSE; - return $status || user_access('translate any entity', $account) || user_access($permission, $account); + return $status || $account->hasPermission('translate any entity') || $account->hasPermission($permission); } /** @@ -587,7 +590,7 @@ function content_translation_enabled($entity_type, $bundle = NULL) { function content_translation_controller($entity_type) { $entity_info = entity_get_info($entity_type); // @todo Throw an exception if the key is missing. - return new $entity_info['controllers']['translation']($entity_type, $entity_info); + return new $entity_info['controllers']['translation']($entity_type, $entity_info, \Drupal::currentUser()); } /** @@ -802,9 +805,8 @@ function content_translation_entity_insert(EntityInterface $entity) { $name = 'translation_' . $key; if (isset($definitions[$name])) { $item = $translation->get($name); - $value = $key != 'uid' ? $item->value : $item->target_id; - if (isset($value)) { - $record[$key] = $value; + if (isset($item->value)) { + $record[$key] = $item->value; } } } diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Access/ContentTranslationManageAccessCheck.php b/core/modules/content_translation/lib/Drupal/content_translation/Access/ContentTranslationManageAccessCheck.php index 16cc31a..ea5e3b0 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Access/ContentTranslationManageAccessCheck.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Access/ContentTranslationManageAccessCheck.php @@ -52,7 +52,7 @@ public function access(Route $route, Request $request, AccountInterface $account $route_requirements = $route->getRequirements(); $operation = $route_requirements['_access_content_translation_manage']; $controller_class = $this->entityManager->getControllerClass($entity_type, 'translation'); - $controller = new $controller_class($entity_type, $entity->entityInfo()); + $controller = new $controller_class($entity_type, $entity->entityInfo(), $account); // Load translation. $translations = $entity->getTranslationLanguages(); diff --git a/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php b/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php index b878550..a34efd7 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Language\Language; +use Drupal\Core\Session\AccountInterface; /** * Base class for content translation controllers. @@ -30,16 +31,26 @@ class ContentTranslationController implements ContentTranslationControllerInterf protected $entityInfo; /** + * The user who is translating the entity. + * + * @var \Drupal\Core\Session\AccountInterface + */ + protected $currentUser; + + /** * Initializes an instance of the content translation controller. * * @param string $entity_type * The type of the entity being translated. * @param array $entity_info * The info array of the given entity type. + * @param \Drupal\Core\Session\AccountInterface + * The user who is translating the entity. */ - public function __construct($entity_type, $entity_info) { + public function __construct($entity_type, $entity_info, $current_user) { $this->entityType = $entity_type; $this->entityInfo = $entity_info; + $this->currentUser = $current_user; } /** @@ -237,7 +248,7 @@ public function entityFormAlter(array &$form, array &$form_state, EntityInterfac // Default to the anonymous user. $name = ''; if ($new_translation) { - $name = $GLOBALS['user']->getUsername(); + $name = $this->currentUser->getUsername(); } elseif ($entity->translation_uid->value) { $name = $entity->translation_uid->entity->getUsername();