class ContentTranslationAccessCheck in Allowed Languages 8
Same name and namespace in other branches
- 2.x src/Access/ContentTranslationAccessCheck.php \Drupal\allowed_languages\Access\ContentTranslationAccessCheck
Allowed languages content translation access check.
Hierarchy
- class \Drupal\allowed_languages\Access\AccessCheckBase implements AccessInterface
- class \Drupal\allowed_languages\Access\ContentTranslationAccessCheck
Expanded class hierarchy of ContentTranslationAccessCheck
1 string reference to 'ContentTranslationAccessCheck'
1 service uses ContentTranslationAccessCheck
File
- src/
Access/ ContentTranslationAccessCheck.php, line 16
Namespace
Drupal\allowed_languages\AccessView source
class ContentTranslationAccessCheck extends AccessCheckBase {
/**
* Drupal entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
private $entityTypeManager;
/**
* Drupal language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
private $languageManager;
/**
* AccessCheck constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* Drupal entity type manager.
* @param \Drupal\Core\Language\LanguageManagerInterface $languageManager
* Drupal language manager.
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager, LanguageManagerInterface $languageManager) {
parent::__construct($entityTypeManager);
$this->entityTypeManager = $entityTypeManager;
$this->languageManager = $languageManager;
}
/**
* 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.
*
* @param \Symfony\Component\Routing\Route $route
* The route to check against.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The parametrized route.
* @param \Drupal\Core\Session\AccountInterface $account
* The currently logged in account.
* @param string $source
* (optional) For a create operation, the language code of the source.
* @param string $target
* (optional) For a create operation, the language code of the translation.
* @param string $language
* (optional) For an update or delete operation, the language code of the
* translation being updated or deleted.
* @param string $entity_type_id
* (optional) The entity type ID.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
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();
}
/**
* Get the target language object.
*
* @param string $target
* The target language id.
*
* @return \Drupal\Core\Language\LanguageInterface
* The target language object or the current content language.
*/
private function getTargetLanguage($target) {
return $this->languageManager
->getLanguage($target) ?: $this->languageManager
->getCurrentLanguage(LanguageInterface::TYPE_CONTENT);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AccessCheckBase:: |
protected | function | Get the allowed languages for the specified user. | |
AccessCheckBase:: |
protected | function | Loads a user entity based on account proxy object. | |
AccessCheckBase:: |
protected | function | Checks if the user is allowed to translate the specified language. | |
ContentTranslationAccessCheck:: |
private | property |
Drupal entity type manager. Overrides AccessCheckBase:: |
|
ContentTranslationAccessCheck:: |
private | property | Drupal language manager. | |
ContentTranslationAccessCheck:: |
public | function | Check language access when managing content translations. | |
ContentTranslationAccessCheck:: |
private | function | Get the target language object. | |
ContentTranslationAccessCheck:: |
public | function |
AccessCheck constructor. Overrides AccessCheckBase:: |