redirect_form_node_form_alter calls getInternalPath on potentially unrouted url

Created on 16 February 2023, almost 2 years ago
Updated 5 January 2024, 12 months ago

Problem/Motivation

As described in a related core issue ( 🐛 Path module calls getInternalPath without checking if the url is routed Needs work ) I'm using a bundle class to override the toUrl() method on a particular node type. In particular, there's a link field that, if populated, will be used by the toUrl() method. The reason is that we want to allow cards to link to internal or external links (or no link whatsoever) as elegantly as possible.

The redirect_form_node_form_alter function is triggering the following exception:

UnexpectedValueException: Unrouted URIs do not have internal representations. in Drupal\Core\Url->getInternalPath()

Steps to reproduce

Use a bundle class with an override for toUrl that results in an unrouted uri for the node.

Proposed resolution

In addition to checking $entity->isNew() also check for $entity->toUrl()->isRouted().

Remaining tasks

User interface changes

N/A

API changes

N/A

Data model changes

N/A

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇺🇸United States danflanagan8 St. Louis, US

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024