This is a follow up to #2743303-22: EntityForm::getEntityFromRouteMatch() does not support route-level parameters.
Problem/Motivation
We recently changed from using _node_add_access which made me realize that _entity_create_access
won't take a default parameter.
Steps to reproduce
Add a route that uses a default instead of a path slug.
my.node.add:
path: '/my/node/add/page'
defaults:
node_type: 'page'
_entity_form: 'node.default'
_title_callback: '\Drupal\node\Controller\NodeController::addPageTitle'
requirements:
_entity_create_access: 'node:{node_type}'
options:
_node_operation_route: TRUE
parameters:
node_type:
type: entity:node_type
When you load the page you should get a 403 Access denied. After applying the patch you should no longer get a 403, but get an error "The website encountered an unexpected error. Please try again later." which applying the patch from #2743303-22: EntityForm::getEntityFromRouteMatch() does not support route-level parameters will fix.
Proposed resolution
Let's call $route_match->getParameters()
instead of getRawParameters()
. getParameters()
resolves default route parameters for us. The description of the related issue says that
Using
$route_match->getRawParameter()
is needed because some parameters are likely to be upcasted
We can just get the ID of the parameter in that case and support default parameters.