public function canView(GroupableInterface $groupable, TokenInterface $token): bool
    {
        $user = $token->getUser();

        // Expirable entities can only be viewed by editors if expired.
        if ($groupable instanceof ExpirableInterface
            && $groupable->isExpired()) {
            $required_role = 'GROUP_ROLE_EDITOR';

        // Active entities can only be viewed by editors if not active.
        } elseif ($groupable instanceof ActiveInterface
            && !$groupable->isActive()) {
            $required_role = 'GROUP_ROLE_EDITOR';

        // Entity can be viewed by group users.
        } else {
            $required_role = 'GROUP_ROLE_USER';
        }

        // Iterate over groups and check access.
        foreach ($groupable->getGroups() as $group) {
            if ($this->decision_manager->decide($token, [$required_role], $group)) {
                return true;
            }
        }

        return false;
    }
public function canView(GroupableInterface $groupable, TokenInterface $token): bool
    {
        $user = $token->getUser();

        // Expirable entities can only be viewed by editors if expired.
        if ($groupable instanceof ExpirableInterface
            && $groupable->isExpired()) {
            $required_role = 'GROUP_ROLE_EDITOR';

        // Active entities can only be viewed by editors if not active.
        } elseif ($groupable instanceof ActiveInterface
            && !$groupable->isActive()) {
            $required_role = 'GROUP_ROLE_EDITOR';

        // Entity can be viewed by group users.
        } else {
            $required_role = 'GROUP_ROLE_USER';
        }

        // Iterate over groups and check access.
        foreach ($groupable->getGroups() as $group) {
            if ($this->decision_manager->decide($token, [$required_role], $group)) {
                return true;
            }
        }

        return false;
    }
public function canView ( GroupableInterface $ groupable , TokenInterface $ token ) : bool { $ user = $ token -> getUser ( ) ; // Expirable entities can only be viewed by editors if expired. if ( $ groupable instanceof ExpirableInterface && $ groupable -> isExpired ( ) ) { $ required_role = 'GROUP_ROLE_EDITOR' ; // Active entities can only be viewed by editors if not active. } elseif ( $ groupable instanceof ActiveInterface && ! $ groupable -> isActive ( ) ) { $ required_role = 'GROUP_ROLE_EDITOR' ; // Entity can be viewed by group users. } else { $ required_role = 'GROUP_ROLE_USER' ; } // Iterate over groups and check access. foreach ( $ groupable -> getGroups ( ) as $ group ) { if ( $ this -> decision_manager -> decide ( $ token , [ $ required_role ] , $ group ) ) { return true ; } } return false ; }
Grants view access to group members for groupable entities.

@param GroupableInterface $groupable The groubale subject.
@param TokenInterface     $token     The user token.

@return bool
Grants view access to group members for groupable entities .