You are here

class SubgroupAddAccessCheck in Subgroup (Graph) 1.0.x

Determines access to for subgroup add forms.

Hierarchy

Expanded class hierarchy of SubgroupAddAccessCheck

1 string reference to 'SubgroupAddAccessCheck'
ggroup.services.yml in ./ggroup.services.yml
ggroup.services.yml
1 service uses SubgroupAddAccessCheck
access_check.ggroup.add in ./ggroup.services.yml
Drupal\ggroup\Access\SubgroupAddAccessCheck

File

src/Access/SubgroupAddAccessCheck.php, line 15

Namespace

Drupal\ggroup\Access
View source
class SubgroupAddAccessCheck implements AccessInterface {

  /**
   * Checks access to the subgroup creation wizard.
   *
   * @param \Symfony\Component\Routing\Route $route
   *   The route to check against.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The currently logged in account.
   * @param \Drupal\group\Entity\GroupInterface $group
   *   The group to create the subgroup in.
   * @param \Drupal\group\Entity\GroupTypeInterface $group_type
   *   The type of subgroup to create in the group.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SubgroupAddAccessCheck::access public function Checks access to the subgroup creation wizard.