Is there a way to specify an argument to pass to a custom access callback, specifically an argument that isn't part of the path? Like in Drupal 7 you could do this:
function mymodule_menu() {
$items['abc/$val'] = array(
'page callback' => 'mymodule_abc_view',
'access callback' => 'mymodule_abcdef_access',
'access arguments' => array(1, 'test1'),
);
$items['def/$val'] = array(
'page callback' => 'mymodule_def_view',
'access callback' => 'mymodule_abcdef_access',
'access arguments' => array(1, 'test2'),
);
return $items;
}
function mymodule_abc_access($val, $type) {
return ($val['some_prop'] == $type);
}
So in Drupal 8 I would have this in mymodule.routing.yml:
mymodule.abc:
path: 'abc/{val}'
defaults:
_controller: '\Drupal\mymodule\Controller\MyModuleController::abc'
requirements:
_custom_access: '\Drupal\mymodule\Controller\MyModuleController::abcDefAccess'
mymodule.def:
path: 'def/{val}'
defaults:
_controller: '\Drupal\mymodule\Controller\MyModuleController::def'
requirements:
_custom_access: '\Drupal\mymodule\Controller\MyModuleController::abcDefAccess'
And in MyModuleController:
public function abcDefAccess($val, $type) {
return AccessResult::allowedIf($val->someProp == $type);
}
But is there any way to pass 'test1' or 'test2' as $type? Otherwise I guess I would just have to make a separate access function for each type.