class ContentTranslationOverviewAccess
Same name in other branches
- 9 core/modules/content_translation/src/Access/ContentTranslationOverviewAccess.php \Drupal\content_translation\Access\ContentTranslationOverviewAccess
- 8.9.x core/modules/content_translation/src/Access/ContentTranslationOverviewAccess.php \Drupal\content_translation\Access\ContentTranslationOverviewAccess
- 10 core/modules/content_translation/src/Access/ContentTranslationOverviewAccess.php \Drupal\content_translation\Access\ContentTranslationOverviewAccess
Access check for entity translation overview.
Hierarchy
- class \Drupal\content_translation\Access\ContentTranslationOverviewAccess implements \Drupal\Core\Routing\Access\AccessInterface
Expanded class hierarchy of ContentTranslationOverviewAccess
1 string reference to 'ContentTranslationOverviewAccess'
- content_translation.services.yml in core/
modules/ content_translation/ content_translation.services.yml - core/modules/content_translation/content_translation.services.yml
1 service uses ContentTranslationOverviewAccess
- content_translation.overview_access in core/
modules/ content_translation/ content_translation.services.yml - Drupal\content_translation\Access\ContentTranslationOverviewAccess
File
-
core/
modules/ content_translation/ src/ Access/ ContentTranslationOverviewAccess.php, line 14
Namespace
Drupal\content_translation\AccessView source
class ContentTranslationOverviewAccess implements AccessInterface {
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a ContentTranslationOverviewAccess object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* Checks access to the translation overview for the entity and bundle.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The parametrized route.
* @param \Drupal\Core\Session\AccountInterface $account
* The currently logged in account.
* @param string $entity_type_id
* The entity type ID.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function access(RouteMatchInterface $route_match, AccountInterface $account, $entity_type_id) {
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $route_match->getParameter($entity_type_id);
if ($entity && $entity->isTranslatable()) {
// Get entity base info.
$bundle = $entity->bundle();
// Get entity access callback.
$definition = $this->entityTypeManager
->getDefinition($entity_type_id);
$translation = $definition->get('translation');
$access_callback = $translation['content_translation']['access_callback'];
$access = call_user_func($access_callback, $entity);
if ($access->isAllowed()) {
return $access;
}
// Check "translate any entity" permission.
if ($account->hasPermission('translate any entity')) {
return AccessResult::allowed()->cachePerPermissions()
->inheritCacheability($access);
}
// Check per entity permission.
$permission = "translate {$entity_type_id}";
if ($definition->getPermissionGranularity() == 'bundle') {
$permission = "translate {$bundle} {$entity_type_id}";
}
return AccessResult::allowedIfHasPermission($account, $permission)->inheritCacheability($access);
}
// No opinion.
return AccessResult::neutral();
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
ContentTranslationOverviewAccess::$entityTypeManager | protected | property | The entity type manager service. |
ContentTranslationOverviewAccess::access | public | function | Checks access to the translation overview for the entity and bundle. |
ContentTranslationOverviewAccess::__construct | public | function | Constructs a ContentTranslationOverviewAccess object. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.