Advertisement
Guest User

Untitled

a guest
Jul 10th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.51 KB | None | 0 0
  1. mycustommodule.register:
  2. path: '/profile/register'
  3. defaults:
  4. _entity_form: 'user.register'
  5. _title: 'Create new account'
  6. requirements:
  7. _access_user_register: 'TRUE'
  8.  
  9. mycustommodule.pass:
  10. path: '/profile/password'
  11. defaults:
  12. _form: 'DrupaluserFormUserPasswordForm'
  13. _title: 'Reset your password'
  14. requirements:
  15. _access: 'TRUE'
  16. options:
  17. _maintenance_access: TRUE
  18.  
  19. mycustommodule.page:
  20. path: '/profile'
  21. defaults:
  22. _controller: 'DrupaluserControllerUserController::userPage'
  23. _title: 'My account'
  24. requirements:
  25. _user_is_logged_in: 'TRUE'
  26.  
  27. mycustommodule.login:
  28. path: '/profile/login'
  29. defaults:
  30. _form: 'DrupaluserFormUserLoginForm'
  31. _title: 'Log in'
  32. requirements:
  33. _user_is_logged_in: 'FALSE'
  34. options:
  35. _maintenance_access: TRUE
  36.  
  37. mycustommodule.login.http:
  38. path: '/profile/login'
  39. defaults:
  40. _controller: DrupaluserControllerUserAuthenticationController::login
  41. methods: [POST]
  42. requirements:
  43. _user_is_logged_in: 'FALSE'
  44. _format: 'json'
  45.  
  46. mycustommodule.login_status.http:
  47. path: '/profile/login_status'
  48. defaults:
  49. _controller: DrupaluserControllerUserAuthenticationController::loginStatus
  50. methods: [GET]
  51. requirements:
  52. _access: 'TRUE'
  53. _format: 'json'
  54.  
  55. mycustommodule.logout.http:
  56. path: '/profile/logout'
  57. defaults:
  58. _controller: DrupaluserControllerUserAuthenticationController::logout
  59. methods: [POST]
  60. requirements:
  61. _user_is_logged_in: 'TRUE'
  62. _format: 'json'
  63. _csrf_token: 'TRUE'
  64.  
  65. mycustommodule.cancel_confirm:
  66. path: '/profile/{user}/cancel/confirm/{timestamp}/{hashed_pass}'
  67. defaults:
  68. _title: 'Confirm account cancellation'
  69. _controller: 'DrupaluserControllerUserController::confirmCancel'
  70. timestamp: 0
  71. hashed_pass: ''
  72. requirements:
  73. _entity_access: 'user.delete'
  74. user: d+
  75.  
  76. mycustommodule.reset.login:
  77. path: '/profile/reset/{uid}/{timestamp}/{hash}/login'
  78. defaults:
  79. _controller: 'DrupaluserControllerUserController::resetPassLogin'
  80. _title: 'Reset password'
  81. requirements:
  82. _user_is_logged_in: 'FALSE'
  83. options:
  84. _maintenance_access: TRUE
  85. no_cache: TRUE
  86.  
  87. mycustommodule.reset:
  88. path: '/profile/reset/{uid}/{timestamp}/{hash}'
  89. defaults:
  90. _controller: 'DrupaluserControllerUserController::resetPass'
  91. _title: 'Reset password'
  92. requirements:
  93. _access: 'TRUE'
  94. options:
  95. _maintenance_access: TRUE
  96. no_cache: TRUE
  97.  
  98. mycustommodule.reset.form:
  99. path: '/profile/reset/{uid}'
  100. defaults:
  101. _controller: 'DrupaluserControllerUserController::getResetPassForm'
  102. _title: 'Reset password'
  103. requirements:
  104. _user_is_logged_in: 'FALSE'
  105. options:
  106. _maintenance_access: TRUE
  107. no_cache: TRUE
  108.  
  109. <?php
  110.  
  111. namespace DrupalmymoduleEventSubscriber;
  112.  
  113. use DrupalCoreRoutingRouteSubscriberBase;
  114. use DrupalCoreRoutingRoutingEvents;
  115. use SymfonyComponentRoutingRouteCollection;
  116.  
  117. class RouteSubscriber extends RouteSubscriberBase {
  118.  
  119. protected function alterRoutes(RouteCollection $collection) {
  120. foreach ($collection->all() as $route) {
  121. if (strpos($route->getPath(), '/user') === 0) {
  122. $route->setPath(preg_replace('/^/user/', '/profile', $route->getPath()));
  123. }
  124. }
  125. }
  126.  
  127.  
  128. public static function getSubscribedEvents() {
  129. $events = parent::getSubscribedEvents();
  130.  
  131. $events[RoutingEvents::ALTER] = array('onAlterRoutes', -250);
  132.  
  133. return $events;
  134. }
  135.  
  136. }
  137.  
  138. services:
  139. mymodule.route_subscriber:
  140. class: DrupalmymoduleEventSubscriberRouteSubscriber
  141. tags:
  142. - { name: event_subscriber }
  143.  
  144. <?php
  145.  
  146. /**
  147. * @file
  148. * Contains DrupalmymoduleRouteOverridePageManagerRoutesOverride.
  149. */
  150.  
  151. namespace DrupalmymoduleRouteOverride;
  152.  
  153. use DrupalCoreRoutingRouteBuildEvent;
  154. use DrupalCoreRoutingRoutingEvents;
  155. use SymfonyComponentEventDispatcherEventSubscriberInterface;
  156. use DrupalCoreExtensionModuleHandlerInterface;
  157. use DrupalComponentDiscoveryYamlDiscovery;
  158.  
  159. /**
  160. * Class PageManagerRoutesOverride
  161. * Overrides paths for the Page Manager module to suit the structure of mymodule.
  162. */
  163. class PageManagerRoutesOverride implements EventSubscriberInterface {
  164.  
  165. /**
  166. * Path to the root of the project.
  167. *
  168. * @var string
  169. */
  170. protected $root;
  171.  
  172. /**
  173. * The module handler service.
  174. *
  175. * @var DrupalCoreExtensionModuleHandlerInterface
  176. */
  177. protected $moduleHandler;
  178.  
  179. /**
  180. * Constructs a new PageManagerRoutesOverride object.
  181. *
  182. * @param string $app_root
  183. * The current application root path.
  184. * @param DrupalCoreExtensionModuleHandlerInterface $module_hander
  185. * The module handler service.
  186. */
  187. public function __construct($app_root, ModuleHandlerInterface $module_hander) {
  188. $this->root = $app_root;
  189. $this->moduleHandler = $module_hander;
  190. }
  191.  
  192. /**
  193. * {@inheritdoc}
  194. */
  195. public static function getSubscribedEvents() {
  196. $events[RoutingEvents::ALTER] = 'alterRoutes';
  197. return $events;
  198. }
  199.  
  200. /**
  201. * Alters existing routes.
  202. *
  203. * @param DrupalCoreRoutingRouteBuildEvent $event
  204. * The route building event.
  205. */
  206. public function alterRoutes(RouteBuildEvent $event) {
  207. // See if the Page Manager UI module is enabled.
  208. if (!$this->moduleHandler->moduleExists('page_manager_ui')) {
  209. return;
  210. }
  211.  
  212. // Page manager has just too many routes and is still quite prone to changes
  213. // so instead of overriding them manually, we'll use the actual route definitions.
  214. $module_directory = $this->moduleHandler->getModule('page_manager_ui')->getPath();
  215. $discovery = new YamlDiscovery('routing', [$this->root . '/' . $module_directory]);
  216. $route_files = $discovery->findAll();
  217.  
  218. // Get the route names.
  219. if (isset($route_files['page_manager_ui'])) {
  220. $route_names = array_keys($route_files['page_manager_ui']);
  221. } else {
  222. $route_names = [];
  223. }
  224.  
  225. // Fetch the collection which can be altered.
  226. $collection = $event->getRouteCollection();
  227.  
  228. // Process the routes.
  229. foreach ($route_names AS $route_name) {
  230. // Fetch the route.
  231. $route = $collection->get($route_name);
  232.  
  233. // Set the new path.
  234. $route_path = strtr($route->getPath(), [
  235. '/admin/structure/page_manager' => '/mymodule/content/page-builder',
  236. '/admin/structure/page_variant' => '/mymodule/content/page-builder'
  237. ]);
  238. $route->setPath($route_path);
  239.  
  240. // Some custom alterations.
  241. switch ($route_name) {
  242. case 'entity.page.collection':
  243. $route->setDefault('_title', 'Page builder');
  244. break;
  245. }
  246. }
  247. }
  248.  
  249. }
  250.  
  251. mymodule.page_manager_routes_override:
  252. class: DrupalmymoduleRouteOverridePageManagerRoutesOverride
  253. arguments: ['@app.root', '@module_handler']
  254. tags:
  255. - { name: event_subscriber }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement