3

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?

1
  • A route subscriber class. See Drupal\node\Routing\RouteSubscriber
    – Eyal
    Jan 20, 2016 at 18:52

2 Answers 2

8

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
  • 2
    Excellent, this was very easy to use and works as advertised. IMHO this should be the accepted answer. Mar 18, 2017 at 22:39
6

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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