Customize the sitemap path

Created on 17 March 2023, about 1 year ago
Updated 15 April 2024, about 2 months ago

Problem/Motivation

Currently, the sitemap module has a hard-coded path at /sitemap.

Sites may want to customize the path to meet their needs.

Proposed resolution

Add a configuration setting, and corresponding field on the Sitemap settings page, to let an administrator set a custom path for the sitemap (the default setting would be /sitemap).

Add a route subscriber to add the sitemap.page route dynamically.

Update existing tests.

Remaining tasks

User interface changes

Add a field to the Sitemap settings page to let an administrator set a custom path for the sitemap.

API changes

Add a route subscriber service (to add the sitemap.page route dynamically).

Data model changes

Add a path configuration setting, of type string, whose default setting is /sitemap.

✨ Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada mparker17 UTC-4

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @mparker17
  • πŸ‡¨πŸ‡¦Canada mparker17 UTC-4

    (fix typo)

  • Status changed to Needs review about 1 year ago
  • πŸ‡¨πŸ‡¦Canada mparker17 UTC-4

    Here is a patch with tests! Reviews welcome!

  • πŸ‡¨πŸ‡¦Canada mparker17 UTC-4

    Added some coding standards fixes.

  • Status changed to Needs work about 1 year ago
  • πŸ‡¨πŸ‡¦Canada mparker17 UTC-4

    I think I will need to add the paths <nolink>, <button>, and <current> to the list of disallowed paths (these are defined in web/core/modules/system/system.routing.yml with <front> and <none>, which are already disallowed).

  • Status changed to Needs review about 1 year ago
  • πŸ‡¨πŸ‡¦Canada mparker17 UTC-4

    Here's an updated patch; reviews welcome. Here's a deeper dive into why I wrote the patch this way...

    The special routes/paths we handle as special cases in the validation function are defined in web/core/modules/system/system.routing.yml as follows...

    '<front>':
      path: '/'
      defaults:
        _title: Home
      requirements:
        _access: 'TRUE'
    
    '<none>':
      path: ''
      options:
        _no_path: TRUE
      requirements:
        _access: 'TRUE'
    
    '<nolink>':
      path: ''
      options:
        _no_path: TRUE
      requirements:
        _access: 'TRUE'
    
    '<button>':
      path: ''
      options:
        _no_path: TRUE
      requirements:
        _access: 'TRUE'
    
    '<current>':
      path: '<current>'
    

    Note that <front> and <current> both have an explicitly-set path (and note that both the route name and path for <current> is the same string); but the other special routes do not.

    Our validation code is looking at paths, not route names. We want to avoid unexpected behavior, so we disallow the paths / and &lt;current&gt;.

    Setting the sitemap path to one of the reserved route names that are not also paths (<front>, <none>, <nolink> and <button>) should work just fine, but it would be confusing to people accustomed to see them interpreted as route names elsewhere in the Drupal UI (and of limited use in the real world), so we disallow those as well.

    ... Hopefully that makes sense!

  • Status changed to RTBC 2 months ago
  • πŸ‡ΊπŸ‡ΈUnited States firewaller

    #6 works for me

  • Merge request !23Issue #3348769: Customize the sitemap path β†’ (Merged) created by mparker17
  • πŸ‡¨πŸ‡¦Canada mparker17 UTC-4

    Awesome, thanks @firewaller!

    I've created a merge request and fixed some lints. If everything works, I will merge tomorrow.

  • πŸ‡¨πŸ‡¦Canada mparker17 UTC-4

    Merged!

  • Status changed to Fixed 2 months ago
  • πŸ‡¨πŸ‡¦Canada mparker17 UTC-4
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024