Drupal 8 provides two default contact forms: "Personal contact form" and "Website feedback." enter image description here

While "Personal contact form" is added to each user's profile by default, to "Website feedback" Drupal automatically provides a link to this form from the footer. The path of this link is "contact" by default. How can I change the path to this contact form, where are those paths generally set and configured?

And by the way, is it possible to change the labels?

  • A route subscriber class. See Drupal\node\Routing\RouteSubscriber – Eyal Jan 20 '16 at 18:52
up vote 5 down vote accepted

I also needed a page at /contact path. With a simple custom module you can change the default routing for the contact forms.

Let's assume custom module is called: example and the new default for the contact forms will be /contactform instead of /contact:

example.services.yml

services:
  example.route_subscriber:
    class: Drupal\example\Routing\RouteSubscriber
    tags:
      - { name: event_subscriber }

src/Routing/RouteSubscriber.php

<?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}');
    }
  }
}
  • 1
    Excellent, this was very easy to use and works as advertised. IMHO this should be the accepted answer. – marcvangend Mar 18 '17 at 22:39

Each form is available at contact/{form_name}. The link on the page that you're looking at points there.

It's not possible to provide a different path, but you can manually create an alias that points to that page.

  • Thank you! And the labels can't be changed neither? – user5950 Jan 20 '16 at 22:59
  • Which labels exactly? – Berdir Jan 21 '16 at 8:05
  • Just created a form, ended with contact/kontakt... Oh really, #Drupal8?! – Alexei Rayu Jan 26 '16 at 20:53

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.