Skip to content

Instantly share code, notes, and snippets.

@gormus
Created September 22, 2016 17:54
Show Gist options
  • Save gormus/33cc8e8ad89194372ea4f00cafe9adef to your computer and use it in GitHub Desktop.
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.
services:
example.route_subscriber:
class: Drupal\example\Routing\RouteSubscriber
tags:
- { name: event_subscriber }
<?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