Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. $items['user'] = array(
  2. 'title' => 'User account',
  3. 'title callback' => 'user_menu_title',
  4. 'weight' => -10,
  5. 'route_name' => 'user_page',
  6. 'menu_name' => 'account',
  7. );
  8.  
  9. user_page:
  10. pattern: '/user'
  11. defaults:
  12. _content: 'DrupaluserControllerUserController::userPage'
  13. requirements:
  14. _access: 'TRUE'
  15.  
  16. // Alter the menu as defined in modules, keys are like user/%user.
  17. drupal_alter('menu', $callbacks);
  18. foreach ($callbacks as $path => $router_item) {
  19. // If the menu item is a default local task and incorrectly references a
  20. // route, remove it.
  21. // @todo This may be removed later depending on the outcome of
  22. // http://drupal.org/node/1889790
  23. if (isset($router_item['type']) && $router_item['type'] == MENU_DEFAULT_LOCAL_TASK) {
  24. unset($callbacks[$path]['route_name']);
  25. }
  26. // If the menu item references a route, normalize the route information
  27. // into the old structure. Note that routes are keyed by name, not path,
  28. // so the path of the route takes precedence.
  29. if (isset($router_item['route_name'])) {
  30. $router_item['page callback'] = 'USES_ROUTE';
  31. $router_item['access callback'] = TRUE;
  32. $new_path = _menu_router_translate_route($router_item['route_name']);
  33.  
  34. unset($callbacks[$path]);
  35. $callbacks[$new_path] = $router_item;
  36. }
  37. }
  38.  
  39. <?php
  40. /**
  41. * @file
  42. * Contains Drupalua_sc_moduleRoutingSearchAlterRouteSubscriber.
  43. */
  44.  
  45. namespace Drupalua_sc_moduleRouting;
  46.  
  47. use DrupalCoreRoutingRouteSubscriberBase;
  48. use SymfonyComponentRoutingRouteCollection;
  49.  
  50. /**
  51. * Listens to the dynamic route events.
  52. */
  53. class SearchAlterRouteSubscriber extends RouteSubscriberBase {
  54.  
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function alterRoutes(RouteCollection $collection) {
  59. // Remove the /search route.
  60. $collection->remove('search.view');
  61. }
  62.  
  63. }
  64.  
  65. <?php
  66.  
  67. use DrupalCoreRoutingRouteBuildEvent;
  68. use DrupalCoreRoutingRoutingEvents;
  69. use SymfonyComponentEventDispatcherEventSubscriberInterface;
  70.  
  71. class RouteSubscriber implements EventSubscriberInterface {
  72.  
  73. /**
  74. * {@inheritdoc}
  75. */
  76. public static function getSubscribedEvents() {
  77. $events[RoutingEvents::ALTER] = 'alterRoutes';
  78. return $events;
  79. }
  80.  
  81. /**
  82. * Alters existing routes.
  83. *
  84. * @param DrupalCoreRoutingRouteBuildEvent $event
  85. * The route building event.
  86. */
  87. public function alterRoutes(RouteBuildEvent $event) {
  88. // Fetch the collection which can be altered.
  89. $collection = $event->getRouteCollection();
  90. // The event is fired multiple times so ensure that the user_page route
  91. // is available.
  92. if ($route = $collection->get('user_page') {
  93. // As example add a new requirement.
  94. $route->setRequirement('_role', 'anonymous');
  95. }
  96. }
  97.  
  98. }
  99.  
  100. services:
  101. mymodule.route_subscriber:
  102. class: DrupalmymoduleRoutingRouteSubscriber
  103. tags:
  104. - { name: event_subscriber }
  105.  
  106. namespace DrupalmymoduleRouting;
  107.  
  108. use DrupalCoreRoutingRouteSubscriberBase;
  109. use SymfonyComponentRoutingRouteCollection;
  110.  
  111. /**
  112. * Listens to the dynamic route events.
  113. */
  114. class RouteSubscriber extends RouteSubscriberBase {
  115.  
  116. /**
  117. * {@inheritdoc}
  118. */
  119. protected function alterRoutes(RouteCollection $collection) {
  120. // Change path '/user/login' to '/login'.
  121. if ($route = $collection->get('user.page')) {
  122. $route->setDefault('_controller', 'DrupalmymoduleControllerUserController::userPage');
  123. }
  124. }
  125.  
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement