Problem/Motivation
Route access is not checked when Operations (Edit/Delete) are rendered
Steps to reproduce
- Create a RouteSubscriber service (like described in
https://www.drupal.org/docs/drupal-apis/routing-system/altering-existing... →
)
- Add a custom access requirement. Example:
...
if ($route = $collection->get('entity.node.edit_form')) {
$route->setRequirement('_custom_access', 'Drupal\my_custom_module\Controller\CustomAccessController::checkEditAccess');
}
...
- update CheckEditAccess so it forbids access to edit_form route
- if you navigate to a node - "Edit" operation is visible, but clicking on "edit" or navigating to edit route will return Access Denied.
Expected: Edit operation should not be rendered
Note: if any route/operations are forbidden in hook_ENTITY_TYPE_access() - there are no issues - route is forbidden and operation "Edit" is not rendered
Note: Delete operation behaves the same - if delete route is forbidden, operation is displayed in local tasks
Note: see Related issues. #2473873 fixes ops in views when route is forbidden by custom access check
Proposed resolution
- either ops should check routes permissions or
- or create OperationsSubscriber to override ops or
- update documentation how to restrict operation when overriding route in case route access and operations are not related
Remaining tasks
- fix issue
- update tests
User interface changes
- none
Introduced terminology
API changes
Data model changes
Release notes snippet