Instead of creating a new route and menu:

  path: '/admin/config/statuscode/config'
    _form: '\Drupal\amu_http_status_code_display\Form\AmuHttpStatusCodeDisplayConfigForm'
    _title: 'HTTP status code error messages'
    _permission: 'administer http status code'

  title: 'AMU HTTP status code'
  description: 'Customize HTTP status code error messages'
  parent: system.admin_config
  route_name: amustatuscode.config
  weight: 100

How can I add this form to the existing basic site settings?


1 Answer 1


You could extend the default form by using a Route subscriber. To do so, create a file named RouteSubscriber.php whithin your module in a src/Routing folder.

the file should look like this:

namespace Drupal\YOUR_MODULE\Routing;

use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;

 * Listens to the dynamic route events.
class RouteSubscriber extends RouteSubscriberBase {

   * {@inheritdoc}
  protected function alterRoutes(RouteCollection $collection) {
    if ($route = $collection->get('system.site_information_settings')) 
      $route->setDefault('_form', 'Drupal\YOUR_MODULE\Form\ExtendedSiteInformationForm');


You should then create a ExtendedSiteInformationForm.php file within your module src/Form folder like that:


namespace Drupal\YOUR_MODULE\Form;

use Drupal\Core\Form\FormStateInterface;
use Drupal\system\Form\SiteInformationForm;

class ExtendedSiteInformationForm extends SiteInformationForm {

   * {@inheritdoc}
  public function buildForm(array $form, FormStateInterface $form_state) {
   $form=  parent::buildForm($form, $form_state);
   //update your $form...
   return $form;

This way you won't need your routing.yml file anymore.

  • mm i am not entering alterRoutes method !?
    – Matoeil
    Sep 15, 2017 at 15:42
  • Then why don't simply use hook_form_FORM_ID_alter($form, $form_state, $form_id)? add your fields and your submit and it should work! Sep 15, 2017 at 15:45
  • @nikko you missed one thing. The RouteSubscriber class must be registered as a service. The module needs a {module_name}.services.yml file registering the class. More details in the link below. drupal.org/docs/8/api/routing-system/… Jan 12, 2018 at 22:25
  • @JorgeCalderon I believe you'd better post a new answer, saying "In complement to Nikko's answer, you should do this and that...." rather than editing actual answer ? Cheers.
    – Kojo
    Jan 13, 2018 at 18:05

Your Answer

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

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