public function SubgroupAddAccessCheck::access in Subgroup (Graph) 1.0.x
Checks access to the subgroup creation wizard.
Parameters
\Symfony\Component\Routing\Route $route: The route to check against.
\Drupal\Core\Session\AccountInterface $account: The currently logged in account.
\Drupal\group\Entity\GroupInterface $group: The group to create the subgroup in.
\Drupal\group\Entity\GroupTypeInterface $group_type: The type of subgroup to create in the group.
Return value
\Drupal\Core\Access\AccessResultInterface The access result.
File
- src/
Access/ SubgroupAddAccessCheck.php, line 32
Class
- SubgroupAddAccessCheck
- Determines access to for subgroup add forms.
Namespace
Drupal\ggroup\AccessCode
public function access(Route $route, AccountInterface $account, GroupInterface $group, GroupTypeInterface $group_type) {
$needs_access = $route
->getRequirement('_subgroup_add_access') === 'TRUE';
// We can only get the group content type ID if the plugin is installed.
$plugin_id = "subgroup:{$group_type->id()}";
if (!$group
->getGroupType()
->hasContentPlugin($plugin_id)) {
return AccessResult::neutral();
}
// Determine whether the user can create groups of the provided type.
$access = $group
->hasPermission("create subgroup:{$group_type->id()} content", $account);
// Only allow access if the user can create subgroups of the provided type
// or if he doesn't need access to do so.
return AccessResult::allowedIf($access xor !$needs_access);
}