Routes fail validation in link field widgets

Created on 21 February 2020, over 4 years ago
Updated 7 July 2023, about 1 year ago

You can add routes to a link field by using route:{$route_name}. However, if you save an entity with a link field that has a route and attempt to edit and re-save the node or menu item without changing the route in the link field, the route will fail validation.

Steps to reproduce

  1. Install a new Drupal site with the Standard profile.
  2. Go to /admin/structure/menu/manage/main/add
  3. Add a menu link to the frontpage view using its route. Enter anything for the title. The path should be route:view.frontpage.page_1. Save your link.
  4. Edit the menu link that you just created. Change the title. Note that the path is now view.frontpage.page_1 instead of route:view.frontpage.page_1. Attempt to save. Note a validation error: Manually entered paths should start with one of the following characters: / ? #

It looks like the code that makes routes fail validation was added to handle display of route:<nolink>:
https://github.com/drupal/drupal/blob/8.9.x/core/modules/link/src/Plugin...

However, route:<nolink> is handled later in the link widget code and other routes are not:
https://github.com/drupal/drupal/blob/8.9.x/core/modules/link/src/Plugin...

Luckily, there is an easy workaround for this bug. Each time you edit an entity with a link field that has a route, simply re-add the route: portion to your link.

🐛 Bug report
Status

Needs review

Version

11.0 🔥

Component
Link 

Last updated 3 days ago

Created by

🇺🇸United States angelamnr

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024