Extended Entity Access for Routes
Categories
Component ID
Component name
Component type
Maintenance status
Development status
Component security advisory coverage
Downloads
Component created
Component changed
Component body
Simplify per-bundle entity access checking for routes. Example: _entity_access: <ENTITY_TYPE>[:<BUNDLE>].<OPERATION>
.
From the developer perspective, this module - just improvement of existing access_check.entity
service. Default implementation - DrupalCoreEntityEntityAccessCheck
- overridden and empowered with possibility to verify entity bundle, if it specified. That's all.
Example
For instance, you want to add a local task to the page of specific entity bundle. To do this you'll just need to define a new route (in example.routing.yml
) and a task itself (in example.links.task.yml
).
example.routing.yml:
example.route:
path: '/admin/structure/types/manage/{node_type}/example-page'
defaults:
_title: 'Example page'
_form: 'DrupalexampleEntityNodeTypeFormExamplePage'
requirements:
_entity_access: 'node_type:article.update'
example.links.task.yml:
example.route:
title: 'Example task'
base_route: entity.node_type.edit_form
route_name: example.route
IMPORTANT: The buildForm()
method of DrupalexampleEntityNodeTypeFormExamplePage
class must contain additional argument, named exactly as entity type (argument type can be omitted).
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, Drupal
odeEntityNodeType $node_type = NULL): array {
return $form;
}
Page and local task as well will not be accessible if this requirement will be ignored.
Additional examples
Check out the entity_access_test module to get more examples.