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
- Install a new Drupal site with the Standard profile.
- Go to
/admin/structure/menu/manage/main/add
- 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. - Edit the menu link that you just created. Change the title. Note that the path is now
view.frontpage.page_1
instead ofroute: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.