Problem/Motivation
I would like to add custom access check to routing entity.group.group_request_membership with RouteSubscriber.
protected function alterRoutes(RouteCollection $collection) {
if ($route = $collection->get('entity.group.group_request_membership')) {
$route->setRequirement('_my_custom_access', 'FALSE');
}
}
The problem is when the modul rendering "Request group membership" or "Request membership" link then it has own logic in code. We must use $url->access($account) to render link when route is available.
When own logic needed it's ok to extend, but I suggest to also use $url->access($account) because if it's false then route is unavailable.
For example:
Old:
if ($group->hasPermission('request group membership', $this->currentUser)) {
$build = $group->toLink($this->t('Request Membership'), 'group-request-membership')
->toString();
}New:
$link = $group->toLink($this->t('Request Membership'), 'group-request-membership');
if($link->getUrl()->access($this->currentUser)){
$build = $link->toString();
}| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 3299945-5.patch | 2.16 KB | kecsot |
| #2 | 3299945-2.patch | 2.2 KB | kecsot |
Issue fork grequest-3299945
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
kecsotComment #3
kecsotComment #4
kecsotComment #5
kecsotnew patch without useless row :)
Comment #8
lobsterr commented@kecsot, I have used your changes and also I added a custom access handler to be sure that we have group request membership plugin enabled. In other case we could get Exception.
Please, check and if it is fine. We can tag another release.
Comment #9
kecsotThank you @LOBsTerr !
Ah! You right, you found a bug. If the plugin is not installed and we go to
/group/{id}/request-membershipthen it throw an exception.I've found an access class in group module called
GroupInstalledContentAccessCheckThis can replace your linkAccess() function.
So I suggest to use it instead of linkAccess.
also I don't understand why did u check 'request group membership' permission in linkAccess function.
What you think?
Comment #10
lobsterr commentedA nice catch, I didn't know it exists. Now it is nice and clean :)
Comment #11
kecsotI've tested it manually.
Works well and code looks good.
Thank you :)
Comment #12
lobsterr commentedThank you for your contribution
Comment #14
lobsterr commented