In D8 you can use custom route arguments:
Passing arguments to controllers
All keys under the defaults section which do not start with an underscore will be passed in as arguments to the controller. Name your arguments appropriately for the arguments of the controller. For example a routing.yml file with the following:
example.content: path: '/example' defaults: _controller: '\Drupal\example\Controller\ExampleController::content' custom_arg: 12 requirements: _permission: 'access content'
Will pass on $custom_arg to the controller, so your content method can take $custom_arg:
public function content(Request $request, $custom_arg) { // Now can use $custom_arg (which will get 12 here) and $request. }
Source: https://www.drupal.org/docs/8/api/routing-system/structure-of-routes
TheWhile the documentation is for a controller, the same applies to other route callbacks, for example a title callback orlike in your case a customan access callback:
public function abcDefAccess($val, $custom_arg) {
return AccessResult::allowedIf($val->someProp == $custom_arg);
}
All of these callbacks share the same code to resolve the arguments from the route.