Ark Development Open Source Standards
latest
  • Introduction
  • Zen Coding and Netbeans Templates
  • Git Tips and Tricks
  • Linux System Administration
  • Drupal Gotcha
  • Front-end Patterns
  • Drupal 8 Reference
    • Request Life Cycle
    • Drush Installation
    • Dependency Injection
    • Config Menu Links
      • Challenge
      • Live Example
      • Assumptions
      • Abstract Guideline:
      • Solution
        • Router Files
        • Links Menu Files
        • Cache Rebuild
      • Common Problems
      • To Do
    • Entity Content
    • Twig Debug
    • Drupal Twig Extension
Ark Development Open Source Standards
  • Docs »
  • Drupal 8 Reference »
  • Drupal 8: Menu Links in Admin Config
  • Edit on GitHub

Drupal 8: Menu Links in Admin Config¶

Drupal 8 admin/config is the place to manage all site

configuration. | Adding custom links under existing sections is easy. | Adding custom sections is not so easy for beginners.

Challenge¶

Add new custom section in admin/config and add several links in this new section.

Live Example¶

This example is taken from Drupal 8 installed instance. Because we have the source code of Drupal 8 in plain text, we can examine how Drupal used its own system to include sections on links in the admin/config page. You can examin how Media section is implemented in the following files: * core/modules/system/system.router.yml * core/modules/system/system.links.menu.yml You’ll find other sections in the same files. And even the implementation of admin/config route iteself.

Assumptions¶

  • All configurations are part of a custom module myModule .
  • You have custom route, that you want to add under new section.
  • Route path: /admin/config/myModule/config
  • Section
    • Title: myModule Configuration
    • path: /admin/config/myModule

Abstract Guideline:¶

  1. Create at least 2 routes, one for the section and any other route to be added as links in this section.
  2. Create at least 2 links, one for the section and any other menu link to be added to this section.

Solution¶

Keep in mind the following information about your module. * Module Path: modules/custom/myModule * Router File: modules/custom/myModule/myModule.router.yml * Links File : modules/custom/myModule/myModule.links.menu.yml Here is the sample code to for the routes.

Router Files¶

Notes
* Route names are arbitary; they can be anything. *

myModule.settings route can be any route with any configuration, there are no mandatory properties. * myModule.adminconfig_ route can have any title, use other properties as is. You can test other path values but at least not _controller property!

Links Menu Files¶

Notes * Menu links names use the same router name for consistancy. Is it a must? * You can include any other configuration link under the new section if you use: parent: myModule.admin_config

Cache Rebuild¶

Rebuild your cache for the new section and links to be visible.

Common Problems¶

The section might not appear after clearing the cache, check the following points: * Spelling of the all router names and menu link names * The section must have at least on link for it to appear in admin/config page * In links.menu.yml file, use link names in parent

To Do¶

  1. Test other properties that may affect the section menu link like weight and position
Next Previous

© Copyright 2016, Ark Development Open Source Ninjas. Revision 618f2b61.

Built with Sphinx using a theme provided by Read the Docs.