Created
September 22, 2016 17:54
-
-
Save gormus/33cc8e8ad89194372ea4f00cafe9adef to your computer and use it in GitHub Desktop.
Drupal 8 - Change the core's default path for `/contact` so that we can use it as an alias.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
example.route_subscriber: | |
class: Drupal\example\Routing\RouteSubscriber | |
tags: | |
- { name: event_subscriber } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Save this file as `src/Routing/RouteSubscriber.php` in your module directory. | |
namespace Drupal\example\Routing; | |
use Drupal\Core\Routing\RouteSubscriberBase; | |
use Symfony\Component\Routing\RouteCollection; | |
/** | |
* Listens to the dynamic route events. | |
*/ | |
class RouteSubscriber extends RouteSubscriberBase { | |
/** | |
* {@inheritdoc} | |
*/ | |
public function alterRoutes(RouteCollection $collection) { | |
// Change the core's default path for `/contact` so that we can use it as an alias. | |
if ($route = $collection->get('contact.site_page')) { | |
$route->setPath('/contactform'); | |
} | |
if ($route = $collection->get('entity.contact_form.canonical')) { | |
$route->setPath('/contactform/{contact_form}'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment