page_example.routing.yml

Same filename in other branches
  1. 4.0.x modules/page_example/page_example.routing.yml
modules/page_example/page_example.routing.yml
2 string references to YAML keys in page_example.routing.yml
page_example_help in modules/page_example/page_example.module
Implements hook_help().
_examples_toolbar_routes in ./examples.module
Get a list of toolbar links to provide.

File

modules/page_example/page_example.routing.yml

View source
  1. # In order to to create pages it is necessary to define routes for them. A route
  2. # maps a URL path to a controller. It defines with what function or method will
  3. # be called when a URL is accessed. The following lines defines three of them
  4. # for this module.
  5. # Menu items corresponding to these URLs are defined separately in the
  6. # page_example.links.menu.yml file.
  7. # If the user accesses http://example.com/?q=examples/page-example, the routing
  8. # system will look for a route with that path. In this case it will find a
  9. # match, and execute the _controller callback. In this case the callback is
  10. # defined as a classname
  11. # ("\Drupal\page_example\Controller\PageExampleController") and a method
  12. # ("description").
  13. # Access to this path is not restricted. This is notated as _access: 'TRUE'.
  14. page_example.description:
  15. path: '/examples/page-example'
  16. defaults:
  17. _controller: '\Drupal\page_example\Controller\PageExampleController::description'
  18. _title: 'Page Example'
  19. requirements:
  20. _permission: 'access content'
  21. # If the user accesses http://example.com/?q=examples/page-example/simple,
  22. # the routing system will look for a route with that path. In this case it will
  23. # find a match, and execute the _controller callback. Access to this path
  24. # requires "access simple page" permission.
  25. page_example.simple:
  26. path: '/examples/page-example/simple'
  27. defaults:
  28. _controller: '\Drupal\page_example\Controller\PageExampleController::simple'
  29. _title: 'Simple - no arguments'
  30. requirements:
  31. _permission: 'access simple page'
  32. # If the user accesses
  33. # http://example.com/?q=examples/page-example/arguments/1/2, the routing system
  34. # will first look for examples/page-example/arguments/1/2. Not finding a match,
  35. # it will look for examples/page-example/arguments/1/{*}. Again not finding a
  36. # match, it will look for examples/page-example/arguments/{*}/2. Yet again not
  37. # finding a match, it will look for examples/page-example/arguments/{*}/{*}.
  38. # This time it finds a match, and so it will execute the _controller callback.
  39. # In this case, it's PageExampleController::arguments().
  40. # Since the parameters are passed to the function after the match, the function
  41. # can do additional checking or make use of them before executing the callback
  42. # function. The placeholder names "first" and "second" are arbitrary but must
  43. # match the variable names in the callback method, e.g. "$first" and "$second".
  44. page_example.arguments:
  45. path: '/examples/page-example/arguments/{first}/{second}'
  46. defaults:
  47. _controller: '\Drupal\page_example\Controller\PageExampleController::arguments'
  48. requirements:
  49. _permission: 'access arguments page'