2

When one navigates to Manage » Configuration, the page is divided into sections which (in the "Seven" theme at least) shows up in individual boxes. These sections have headings like "People", "Content authoring", "Development", etc.

I am able to create a settings form and place this inside any of the existing sections on the configuration page by associating it with the parent key in hello_world.links.menu.yml.

Example:

hello_world.greeting_form:
  title: 'Salutation settings'
  description: 'Configure the salutation message.'
  route_name: hello_world.greeting_form
  parent: system.admin_config_development

This places a link to the settings form for the "Hello World" module in the "Development" section. This is not where I want to place it.

Instead, I want to create a new section named "Examples", place this new section along with the others on the "Configuration" page, and make this new section the parent of my link to the settings form.

Below is an image of what I want it to look like. There should be a new section, named "Examples" as the section heading, and in that section, there should be a link to the settings form with the text "Salutation settings":

enter image description here

2
  • if that is not the place you want the menu item. Can you share screen shot of where its needed so will update my answer. – miststudent2011 Apr 21 at 2:48
  • No, that is not where I want it. I've added a screen shot as suggested to better show what I am looking for. – Free Radical Apr 23 at 12:21
1

Here is a way to do it.

#example_codes.links.menu.yml

example_codes.base:
  title: 'Example Codes Module'
  parent: system.admin
  description: 'A Module with various Examples.'
  route_name: example_codes.base
  weight: 0

You need to define system.admin as parent.

And in your routing.yml should contain this base route.

#example_codes.routing.yml

example_codes.base:
  path: '/admin/examples-codes'
  defaults:
    _controller: '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage'
    _title: 'Example Codes Module'
  requirements:
    _permission: 'administer example codes configurations'
1
  • Thank you for taking time answering. Your code works, but places the link alongside "Configuration" within the admin toolbar. I want a new section to appear on the "Configuration" page. I've added a mock-up image of what it is I try to achieve. – Free Radical Apr 23 at 12:23
1

The yaml-files that do this for the core is located in core/modules/system/. I eventually solved it by copying and adapting the relevant bits from system.routing.ymland system.links.menu.yml.

First, in hello_world.routing.yml, set up the routings we shall need:

hello_world.admin_config_examples:
  path: '/admin/config/examples'
  defaults:
    _controller: '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage'
    _title: 'Examples'
  requirements:
    _permission: 'access administration pages'

hello_world.greeting_form:
  path: '/admin/config/examples/salutation-configuration'
  defaults:
    _form: Drupal\hello_world\Form\SalutationConfigurationForm
    _title: 'Salutation configuration'
  requirements:
    _permission: 'administer site configuration'

Then, in hello_world.links.menu.yml, set up menu items. First the item that is going to be link to the section, and then the the menu item that links to the settings form:

hello_world.admin_config_examples:
  title: 'Examples'
  route_name: hello_world.admin_config_examples
  parent: system.admin_config
  weight: 0
hello_world.greeting_form:
  title: 'Salutation settings'
  description: 'Configure the salutation message.'
  route_name: hello_world.greeting_form
  parent: hello_world.admin_config_examples
1
  • you beat me here. yes, that was exact change system.admin_config . Glad you figured it out. – miststudent2011 Apr 23 at 16:35

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.