Skip to main content
deleted 65 characters in body
Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

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.

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

The same applies to other callbacks, for example a title callback or in your case a custom 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.

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

While the documentation is for a controller, the same applies to other route callbacks, like in your case an access callback:

public function abcDefAccess($val, $custom_arg) {
  return AccessResult::allowedIf($val->someProp == $custom_arg);
}
add example
Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

YouIn 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' 
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.
  }
  // ...
  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

The same applies to other callbacks, for example a title callback or in your case a custom 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.

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

The same applies to other callbacks, a title or in your case a custom access callback.

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

The same applies to other callbacks, for example a title callback or in your case a custom 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.

added 5 characters in body
Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

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

The same applies forto other callbacks, a title or in your case ana custom access callback.

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

The same applies for other callbacks, a title or in your case an access callback.

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

The same applies to other callbacks, a title or in your case a custom access callback.

Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217
Loading