Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $items['user'] = array(
- 'title' => 'User account',
- 'title callback' => 'user_menu_title',
- 'weight' => -10,
- 'route_name' => 'user_page',
- 'menu_name' => 'account',
- );
- user_page:
- pattern: '/user'
- defaults:
- _content: 'DrupaluserControllerUserController::userPage'
- requirements:
- _access: 'TRUE'
- // Alter the menu as defined in modules, keys are like user/%user.
- drupal_alter('menu', $callbacks);
- foreach ($callbacks as $path => $router_item) {
- // If the menu item is a default local task and incorrectly references a
- // route, remove it.
- // @todo This may be removed later depending on the outcome of
- // http://drupal.org/node/1889790
- if (isset($router_item['type']) && $router_item['type'] == MENU_DEFAULT_LOCAL_TASK) {
- unset($callbacks[$path]['route_name']);
- }
- // If the menu item references a route, normalize the route information
- // into the old structure. Note that routes are keyed by name, not path,
- // so the path of the route takes precedence.
- if (isset($router_item['route_name'])) {
- $router_item['page callback'] = 'USES_ROUTE';
- $router_item['access callback'] = TRUE;
- $new_path = _menu_router_translate_route($router_item['route_name']);
- unset($callbacks[$path]);
- $callbacks[$new_path] = $router_item;
- }
- }
- <?php
- /**
- * @file
- * Contains Drupalua_sc_moduleRoutingSearchAlterRouteSubscriber.
- */
- namespace Drupalua_sc_moduleRouting;
- use DrupalCoreRoutingRouteSubscriberBase;
- use SymfonyComponentRoutingRouteCollection;
- /**
- * Listens to the dynamic route events.
- */
- class SearchAlterRouteSubscriber extends RouteSubscriberBase {
- /**
- * {@inheritdoc}
- */
- public function alterRoutes(RouteCollection $collection) {
- // Remove the /search route.
- $collection->remove('search.view');
- }
- }
- <?php
- use DrupalCoreRoutingRouteBuildEvent;
- use DrupalCoreRoutingRoutingEvents;
- use SymfonyComponentEventDispatcherEventSubscriberInterface;
- class RouteSubscriber implements EventSubscriberInterface {
- /**
- * {@inheritdoc}
- */
- public static function getSubscribedEvents() {
- $events[RoutingEvents::ALTER] = 'alterRoutes';
- return $events;
- }
- /**
- * Alters existing routes.
- *
- * @param DrupalCoreRoutingRouteBuildEvent $event
- * The route building event.
- */
- public function alterRoutes(RouteBuildEvent $event) {
- // Fetch the collection which can be altered.
- $collection = $event->getRouteCollection();
- // The event is fired multiple times so ensure that the user_page route
- // is available.
- if ($route = $collection->get('user_page') {
- // As example add a new requirement.
- $route->setRequirement('_role', 'anonymous');
- }
- }
- }
- services:
- mymodule.route_subscriber:
- class: DrupalmymoduleRoutingRouteSubscriber
- tags:
- - { name: event_subscriber }
- namespace DrupalmymoduleRouting;
- use DrupalCoreRoutingRouteSubscriberBase;
- use SymfonyComponentRoutingRouteCollection;
- /**
- * Listens to the dynamic route events.
- */
- class RouteSubscriber extends RouteSubscriberBase {
- /**
- * {@inheritdoc}
- */
- protected function alterRoutes(RouteCollection $collection) {
- // Change path '/user/login' to '/login'.
- if ($route = $collection->get('user.page')) {
- $route->setDefault('_controller', 'DrupalmymoduleControllerUserController::userPage');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement