public function GroupLatestRevisionCheck::access in Group 8
Same name and namespace in other branches
- 2.0.x src/Entity/Access/GroupLatestRevisionCheck.php \Drupal\group\Entity\Access\GroupLatestRevisionCheck::access()
Checks that there is a pending revision available.
This checker assumes the presence of an '_entity_access' requirement key in the same form as used by EntityAccessCheck.
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 current user account.
Return value
\Drupal\Core\Access\AccessResultInterface The access result.
See also
\Drupal\Core\Entity\EntityAccessCheck
File
- src/
Entity/ Access/ GroupLatestRevisionCheck.php, line 71
Class
- GroupLatestRevisionCheck
- Access check for the group moderation tab.
Namespace
Drupal\group\Entity\AccessCode
public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) {
/** @var \Drupal\group\Entity\GroupInterface $group */
$group = $route_match
->getParameter('group');
// This tab should not show up unless there's a reason to show it.
if (!$this->moderationInfo
->hasPendingRevision($group)) {
return AccessResult::forbidden('No pending revision for this group.')
->addCacheableDependency($group);
}
// Unlike Drupal core, we allow revision viewing if you have 'view' access
// to the group along with the 'view latest group version' group permission.
// This allows access modules to have more say over who can view revisions,
// rather than having to swap out this class to add permissions.
//
// See core issue: https://www.drupal.org/project/drupal/issues/2943471.
$storage = $this->entityTypeManager
->getStorage('group');
$group_revision = $storage
->loadRevision($storage
->getLatestTranslationAffectedRevisionId($group
->id(), $group
->language()
->getId()));
return GroupAccessResult::allowedIfHasGroupPermission($group, $account, 'view latest group version')
->andIf($group_revision
->access('view', $account, TRUE));
}