2

Instead of creating a new route and menu:

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


amustatuscode.config:
  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?

/admin/config/system/site-information

2

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:

<?php 
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:

<?php

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 '17 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! – Drupal de Comptoir Sep 15 '17 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/… – Jorge Calderon Jan 12 '18 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 '18 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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