2

How can I add a section to the admin/config route and populate it with my own modules? In Drupal 7 it was easy, but I can't figure it out now in Drupal 8. The closest I can get is adding my modules to the Configuration Menu List that appears in the sidebar.

module.links.menu.yml

module.admin_settings:
  title: 'Module Admin Title'
  description: 'Module Admin Desc.'
  route_name: my_module.my_module_settings
  parent: system.admin_config

3 Answers 3

1

You must add a menu link and a router item for the page:

  1. Add a menu link in my_module.links.menu.yml. See core/modules/system/system.links.menu.yml:

    my_module.my_group_menu:
      parent: system.admin_config
      route_name: my_module.my_group
    
  2. Add a router item in my_module.routing.yml, which can re-use the same controller: SystemController::systemAdminBlockPage(). See core/modules/system/system.routing.yml for an example.

    my_module.my_group:
      path: '/admin/config/my-group'
    
  3. Then add your menu link to your settings page as a parent to the menu link you created in #1.

3
  • Just I started Drupal8. So as u mentioned above parent: system.admin_config. If I used this I will get section name as CONFIGURATION bcz ts mentioned in that particular route. I want to create seperate section with my own choce of name. Is it possible or not. I dont want to use already defined route paths.
    – Suraj
    May 26, 2017 at 13:59
  • Yes, you would make the parent my_module.admin_SECTION and define a menu link for that as well and make its parent system.admin. Then make a corresponding route that is exactly like in system.routing.yml. See the answer above for all the respective links you need to look at for what I mentioned in this comment. If you have additional issues, post a new question and provide your routing and links.menu YAML files.
    – mradcliffe
    May 30, 2017 at 21:37
  • I have posted a new question please have a look at it. drupal.stackexchange.com/questions/237507/…
    – Suraj
    Jun 1, 2017 at 12:54
2

You should assign your menu link to one of the specific groups on /admin/config by setting the correct path. You can find most of them in system.links.menu.yml and it usually matches the path, e.g. parent: system.admin_config_media.

2
  • 2
    But how would I add my own group, Berdir?
    – EmGee
    Dec 2, 2015 at 14:13
  • @EmGee – See @commonpike's answer below. You need to create a new parent route first, which calls \Drupal\system\Controller\SystemController::systemAdminMenuBlockPage.
    – leymannx
    Apr 9, 2022 at 14:20
2

The accepted answer is right, but I found it hard to understand.

The sections on admin/config are actually a page. Take a look at the breadcrumbs after clicking on 'basic site settings': you can click up one level to a page for system.

So you need two links, and two routes. The first link defines a page you will rarely use, but also creates the block on the admin/config page.

mymodule.links.menu.yaml:

system.admin_config_mysite:
  route_name: system.admin_config_mysite
  parent: system.admin_config
  title: MySite Settings
  description: 'Configure MySite'
  weight: 100
  
mymodule.settings:
  title: 'MyModule Settings'
  parent: system.admin_config_mysite
  description: 'Settings for MyModule'
  route_name: mymodule.settings
  weight: 100

mymodule.routing.yml

system.admin_config_mysite:
  path: '/admin/config/mysite'
  defaults:
    _controller: '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage'
    _title: 'MySite Settings'
    _title_context: 'mysite'
  requirements:
    _permission: 'access administration pages'
    
mymodule.settings:
  path: '/admin/config/mysite/mymodule'
  defaults:
    _form: '\Drupal\mymodule\Form\MyModuleSettingsForm'
    _title: 'MyModule Settings'
    _title_context: 'mysite'
  requirements:
    _permission: 'administer site configuration'

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.