You are here

public function ContentTranslationAccessCheck::access in Allowed Languages 8

Same name and namespace in other branches
  1. 2.x src/Access/ContentTranslationAccessCheck.php \Drupal\allowed_languages\Access\ContentTranslationAccessCheck::access()

Check language access when managing content translations.

This access check is based on the access check provided by the content translation module and uses the same parameters in the access callback.

Parameters

\Symfony\Component\Routing\Route $route: The route to check against.

\Drupal\Core\Routing\RouteMatchInterface $route_match: The parametrized route.

\Drupal\Core\Session\AccountInterface $account: The currently logged in account.

string $source: (optional) For a create operation, the language code of the source.

string $target: (optional) For a create operation, the language code of the translation.

string $language: (optional) For an update or delete operation, the language code of the translation being updated or deleted.

string $entity_type_id: (optional) The entity type ID.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

File

src/Access/ContentTranslationAccessCheck.php, line 75

Class

ContentTranslationAccessCheck
Allowed languages content translation access check.

Namespace

Drupal\allowed_languages\Access

Code

public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account, $source = NULL, $target = NULL, $language = NULL, $entity_type_id = NULL) {

  /* @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  $entity = $route_match
    ->getParameter($entity_type_id);

  // If the entity could not be found on the parameters let other modules
  // take care of the access check.
  if (!$entity) {
    return AccessResult::neutral();
  }
  $user = $this
    ->loadUserEntityFromAccountProxy($account);
  $target_language = $this
    ->getTargetLanguage($target);
  if ($this
    ->userIsAllowedToTranslateLanguage($user, $target_language)) {
    return AccessResult::allowed();
  }
  return AccessResult::forbidden();
}