Problem/Motivation

As described in a related core issue (#3342398: Path module calls getInternalPath without checking if the url is routed) 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

Issue fork redirect-3342409

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

danflanagan8 created an issue. See original summary.

danflanagan8’s picture

Status: Active » Needs review
StatusFileSize
new622 bytes

Here's a hopefully inoffensive patch.

dpi’s picture

Thanks for the patch, just what I needed.

mahtab_alam made their first commit to this issue’s fork.

mlncn’s picture

Status: Needs review » Reviewed & tested by the community

Working, and the code is a straightforward minimal validity check.

mlncn’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

Frustratingly, instead of being committed, this now needs a re-roll :-/

mlncn changed the visibility of the branch 3342409-avoid-internal-path-call-on-unrouted-url to hidden.

mlncn changed the visibility of the branch 3342409-avoid-internal-path-call-on-unrouted-url to active.

mlncn changed the visibility of the branch 3342409-redirectformnodeformalter-calls-getinternalpath to hidden.

dpi’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll

Pushed 8.x-1.x to fork repo so the diff isnt 73 pages long. Back to one line.

mlncn’s picture

Ah so that is what the problem is. Wherever that is documented i must always get that wrong, despite having tried in the past both with manual instructions and the rebase button in GitLab; it had seemed the catch-up rebase itself was the problem. Thanks. Also thought i had fixed it in https://git.drupalcode.org/project/redirect/-/merge_requests/164.diff (in that it was one line and useable, at least).

Either way, despite the maddening fork PLUS branch setup of Drupal issues, yes straightforward re-roll (the lines above had been changed to be better self-documentation) and back to RTBC.

dpi’s picture

Yeah, I'm sure this workflow quirk causes a tonne of unnecessary rebases and new MR's being created

mighty_webber’s picture

StatusFileSize
new597 bytes

Patch for Drupal 10.4.9

mably changed the visibility of the branch 8.x-1.x to hidden.