menu_example.routing.yml

Same filename in other branches
  1. 8.x-1.x menu_example/menu_example.routing.yml
  2. 4.0.x modules/menu_example/menu_example.routing.yml
modules/menu_example/menu_example.routing.yml
8 string references to YAML keys in menu_example.routing.yml
MenuExampleController::customAccess in modules/menu_example/src/Controller/MenuExampleController.php
Demonstrates the use of custom access check in routes.
MenuExampleController::permissioned in modules/menu_example/src/Controller/MenuExampleController.php
A menu entry with simple permissions using 'access protected menu example'.
MenuExampleController::placeholderArgs in modules/menu_example/src/Controller/MenuExampleController.php
Demonstrates how you can provide a placeholder url arguments.
MenuExampleController::routeOnly in modules/menu_example/src/Controller/MenuExampleController.php
Give the user a link to the route-only page.
MenuExampleController::urlArgument in modules/menu_example/src/Controller/MenuExampleController.php
Demonstrates use of optional URL arguments in for menu item.

... See full list

File

modules/menu_example/menu_example.routing.yml

View source
  1. # This file contains routing entries which is then read by Drupal to match
  2. # a particular request which a corresponding path. A particular route entry
  3. # is bound to the URI defined using 'path' key, the 'access content' permission
  4. # is checked on the accessing user and, if access is granted, the
  5. # MenuExampleController::{methodName} method is invoked and a page is displayed
  6. # with defined response.
  7. # '_controller' defines the controller class and it's method which Drupal's
  8. # autoload mechanism looks for, creating the response from.
  9. #
  10. examples.menu_example: # This is a route name.
  11. path: '/examples/menu-example'
  12. defaults:
  13. _controller: '\Drupal\menu_example\Controller\MenuExampleController::description'
  14. _title: 'Menu Example'
  15. requirements:
  16. _permission: 'access content'
  17. # This menu entry will appear as main menu tab instead of tools menu.
  18. # In menu_example.links.menu.yml we have used 'menu_name' as 'main' which links
  19. # the menu entry to main navigation menu.
  20. examples.menu_example.alternate_menu:
  21. path: '/examples/menu-example-alternate-menu'
  22. defaults:
  23. _controller: '\Drupal\menu_example\Controller\MenuExampleController::alternateMenu'
  24. _title: 'Menu Example: Menu in alternate menu'
  25. requirements:
  26. _permission: 'access content'
  27. # The menu entry demonstrates the use of permissions to restrict access
  28. # to a particular path until and unless the requirement is met.
  29. examples.menu_example.permissioned:
  30. path: '/examples/menu-example/permissioned'
  31. defaults:
  32. _controller: '\Drupal\menu_example\Controller\MenuExampleController::permissioned'
  33. _title: 'Permissioned Route Example'
  34. requirements:
  35. _permission: 'access content'
  36. # Only the user with the required permission will be able to access this route.
  37. examples.menu_example.permissioned_controlled:
  38. path: '/examples/menu-example/permissioned/controlled'
  39. defaults:
  40. _controller: '\Drupal\menu_example\Controller\MenuExampleController::permissionedControlled'
  41. _title: 'Permissioned Route'
  42. requirements:
  43. _permission: 'access protected menu example'
  44. # Sometimes just relying on permissions and/or roles is not sufficient
  45. # and you need to do custom access checking on routes.
  46. examples.menu_example.custom_access:
  47. path: '/examples/menu-example/custom-access'
  48. defaults:
  49. _controller: '\Drupal\menu_example\Controller\MenuExampleController::customAccess'
  50. _title: 'Custom Access Example'
  51. requirements:
  52. _permission: 'access content'
  53. # Custom access is called once this route is requested.
  54. # Check src/Access/RoleAccessCheck.php
  55. examples.menu_example.custom_access_page:
  56. path: '/examples/menu-example/custom-access/page'
  57. defaults:
  58. _controller: '\Drupal\menu_example\Controller\MenuExampleController::customAccessPage'
  59. _title: 'Custom Access Menu Item'
  60. requirements:
  61. _menu_example_role: 'TRUE'
  62. # This route has a corresponding menu entry, so the user can click on it in the
  63. # UI. This gives them a link to a route with no menu entry.
  64. examples.menu_example.route_only:
  65. path: '/examples/menu-example/route-only'
  66. defaults:
  67. _controller: '\Drupal\menu_example\Controller\MenuExampleController::routeOnly'
  68. _title: 'Route only example'
  69. requirements:
  70. _permission: 'access content'
  71. # These type of routes can be used to create webservices.
  72. examples.menu_example.route_only.callback:
  73. path: '/examples/menu-example/route-only/callback'
  74. defaults:
  75. _controller: '\Drupal\menu_example\Controller\MenuExampleController::routeOnlyCallback'
  76. _title: 'Callback only'
  77. requirements:
  78. _permission: 'access content'
  79. # Drupal 8's routes may include placeholder elements which designate places
  80. # where the URL contains dynamic values. In the controller method, this value
  81. # is available when a variable with the same name is used in the controller
  82. # method. Matching the variable name is must. The {arg} element in the URL is
  83. # called a slug and is available as a $arg in the controller method.
  84. examples.menu_example.use_url_arguments:
  85. path: '/examples/menu-example/use-url-arguments/{arg1}/{arg2}'
  86. defaults:
  87. _title: 'URL Arguments'
  88. _controller: '\Drupal\menu_example\Controller\MenuExampleController::urlArgument'
  89. # We provide default value to both arguments.
  90. arg1: ''
  91. arg2: ''
  92. requirements:
  93. _permission: 'access content'
  94. # Title of this menu entry will be altered by controller method defined by
  95. # key '_title_callback'.
  96. examples.menu_example.title_callbacks:
  97. path: '/examples/menu-example/title-callbacks'
  98. defaults:
  99. _title_callback: 'Drupal\menu_example\Controller\MenuExampleController::titleCallback'
  100. _controller: '\Drupal\menu_example\Controller\MenuExampleController::titleCallbackContent'
  101. requirements:
  102. _permission: 'access content'
  103. # A menu item entry to demonstrate use of parameters in routes.
  104. examples.menu_example.placeholder_argument:
  105. path: '/examples/menu-example/placeholder-argument'
  106. defaults:
  107. _title: 'Placeholder Arguments'
  108. _controller: '\Drupal\menu_example\Controller\MenuExampleController::placeholderArgs'
  109. requirements:
  110. _permission: 'access content'
  111. # Parameters in routes can be used as placeholders arguments too.
  112. examples.menu_example.placeholder_argument.display:
  113. path: '/examples/menu-example/placeholder-argument/{arg}/display'
  114. defaults:
  115. _title: 'Placeholder Arguments'
  116. _controller: '\Drupal\menu_example\Controller\MenuExampleController::placeholderArgsDisplay'
  117. requirements:
  118. arg: \d+
  119. _permission: 'access content'
  120. # Any route defined here can be altered. We can do so by defining a RouteSubscriber!
  121. example.menu_example.path_override:
  122. path: '/examples/menu-example/menu-original-path'
  123. defaults:
  124. _title: 'Menu path that will be altered'
  125. _controller: '\Drupal\menu_example\Controller\MenuExampleController::pathOverride'
  126. requirements:
  127. _permission: 'access content'
  128. # Dynamic routes are implemented in a method. This method is added as a
  129. # 'route_callbacks'
  130. route_callbacks:
  131. - '\Drupal\menu_example\Routing\MenuExampleDynamicRoutes::routes'