Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mycustommodule.register:
- path: '/profile/register'
- defaults:
- _entity_form: 'user.register'
- _title: 'Create new account'
- requirements:
- _access_user_register: 'TRUE'
- mycustommodule.pass:
- path: '/profile/password'
- defaults:
- _form: 'DrupaluserFormUserPasswordForm'
- _title: 'Reset your password'
- requirements:
- _access: 'TRUE'
- options:
- _maintenance_access: TRUE
- mycustommodule.page:
- path: '/profile'
- defaults:
- _controller: 'DrupaluserControllerUserController::userPage'
- _title: 'My account'
- requirements:
- _user_is_logged_in: 'TRUE'
- mycustommodule.login:
- path: '/profile/login'
- defaults:
- _form: 'DrupaluserFormUserLoginForm'
- _title: 'Log in'
- requirements:
- _user_is_logged_in: 'FALSE'
- options:
- _maintenance_access: TRUE
- mycustommodule.login.http:
- path: '/profile/login'
- defaults:
- _controller: DrupaluserControllerUserAuthenticationController::login
- methods: [POST]
- requirements:
- _user_is_logged_in: 'FALSE'
- _format: 'json'
- mycustommodule.login_status.http:
- path: '/profile/login_status'
- defaults:
- _controller: DrupaluserControllerUserAuthenticationController::loginStatus
- methods: [GET]
- requirements:
- _access: 'TRUE'
- _format: 'json'
- mycustommodule.logout.http:
- path: '/profile/logout'
- defaults:
- _controller: DrupaluserControllerUserAuthenticationController::logout
- methods: [POST]
- requirements:
- _user_is_logged_in: 'TRUE'
- _format: 'json'
- _csrf_token: 'TRUE'
- mycustommodule.cancel_confirm:
- path: '/profile/{user}/cancel/confirm/{timestamp}/{hashed_pass}'
- defaults:
- _title: 'Confirm account cancellation'
- _controller: 'DrupaluserControllerUserController::confirmCancel'
- timestamp: 0
- hashed_pass: ''
- requirements:
- _entity_access: 'user.delete'
- user: d+
- mycustommodule.reset.login:
- path: '/profile/reset/{uid}/{timestamp}/{hash}/login'
- defaults:
- _controller: 'DrupaluserControllerUserController::resetPassLogin'
- _title: 'Reset password'
- requirements:
- _user_is_logged_in: 'FALSE'
- options:
- _maintenance_access: TRUE
- no_cache: TRUE
- mycustommodule.reset:
- path: '/profile/reset/{uid}/{timestamp}/{hash}'
- defaults:
- _controller: 'DrupaluserControllerUserController::resetPass'
- _title: 'Reset password'
- requirements:
- _access: 'TRUE'
- options:
- _maintenance_access: TRUE
- no_cache: TRUE
- mycustommodule.reset.form:
- path: '/profile/reset/{uid}'
- defaults:
- _controller: 'DrupaluserControllerUserController::getResetPassForm'
- _title: 'Reset password'
- requirements:
- _user_is_logged_in: 'FALSE'
- options:
- _maintenance_access: TRUE
- no_cache: TRUE
- <?php
- namespace DrupalmymoduleEventSubscriber;
- use DrupalCoreRoutingRouteSubscriberBase;
- use DrupalCoreRoutingRoutingEvents;
- use SymfonyComponentRoutingRouteCollection;
- class RouteSubscriber extends RouteSubscriberBase {
- protected function alterRoutes(RouteCollection $collection) {
- foreach ($collection->all() as $route) {
- if (strpos($route->getPath(), '/user') === 0) {
- $route->setPath(preg_replace('/^/user/', '/profile', $route->getPath()));
- }
- }
- }
- public static function getSubscribedEvents() {
- $events = parent::getSubscribedEvents();
- $events[RoutingEvents::ALTER] = array('onAlterRoutes', -250);
- return $events;
- }
- }
- services:
- mymodule.route_subscriber:
- class: DrupalmymoduleEventSubscriberRouteSubscriber
- tags:
- - { name: event_subscriber }
- <?php
- /**
- * @file
- * Contains DrupalmymoduleRouteOverridePageManagerRoutesOverride.
- */
- namespace DrupalmymoduleRouteOverride;
- use DrupalCoreRoutingRouteBuildEvent;
- use DrupalCoreRoutingRoutingEvents;
- use SymfonyComponentEventDispatcherEventSubscriberInterface;
- use DrupalCoreExtensionModuleHandlerInterface;
- use DrupalComponentDiscoveryYamlDiscovery;
- /**
- * Class PageManagerRoutesOverride
- * Overrides paths for the Page Manager module to suit the structure of mymodule.
- */
- class PageManagerRoutesOverride implements EventSubscriberInterface {
- /**
- * Path to the root of the project.
- *
- * @var string
- */
- protected $root;
- /**
- * The module handler service.
- *
- * @var DrupalCoreExtensionModuleHandlerInterface
- */
- protected $moduleHandler;
- /**
- * Constructs a new PageManagerRoutesOverride object.
- *
- * @param string $app_root
- * The current application root path.
- * @param DrupalCoreExtensionModuleHandlerInterface $module_hander
- * The module handler service.
- */
- public function __construct($app_root, ModuleHandlerInterface $module_hander) {
- $this->root = $app_root;
- $this->moduleHandler = $module_hander;
- }
- /**
- * {@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) {
- // See if the Page Manager UI module is enabled.
- if (!$this->moduleHandler->moduleExists('page_manager_ui')) {
- return;
- }
- // Page manager has just too many routes and is still quite prone to changes
- // so instead of overriding them manually, we'll use the actual route definitions.
- $module_directory = $this->moduleHandler->getModule('page_manager_ui')->getPath();
- $discovery = new YamlDiscovery('routing', [$this->root . '/' . $module_directory]);
- $route_files = $discovery->findAll();
- // Get the route names.
- if (isset($route_files['page_manager_ui'])) {
- $route_names = array_keys($route_files['page_manager_ui']);
- } else {
- $route_names = [];
- }
- // Fetch the collection which can be altered.
- $collection = $event->getRouteCollection();
- // Process the routes.
- foreach ($route_names AS $route_name) {
- // Fetch the route.
- $route = $collection->get($route_name);
- // Set the new path.
- $route_path = strtr($route->getPath(), [
- '/admin/structure/page_manager' => '/mymodule/content/page-builder',
- '/admin/structure/page_variant' => '/mymodule/content/page-builder'
- ]);
- $route->setPath($route_path);
- // Some custom alterations.
- switch ($route_name) {
- case 'entity.page.collection':
- $route->setDefault('_title', 'Page builder');
- break;
- }
- }
- }
- }
- mymodule.page_manager_routes_override:
- class: DrupalmymoduleRouteOverridePageManagerRoutesOverride
- arguments: ['@app.root', '@module_handler']
- tags:
- - { name: event_subscriber }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement