deleteEntityPathAll calls getInternalPath on potentially unrouted url

Created on 3 May 2023, about 1 year ago
Updated 23 November 2023, 7 months ago

Problem/Motivation

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 code looks like this:

  public function toUrl($rel = 'canonical', array $options = []) {
    if ($rel === 'canonical') {
      if (!empty($this->field_link->uri)) {
        return Url::fromUri($this->field_link->uri);
      }
      else {
        return Url::fromRoute('<nolink>');
      }
    }
    return parent::toUrl($rel, $options);
  }

This exposed some bugs in core ( ๐Ÿ› Path module calls getInternalPath without checking if the url is routed Needs work ) and Redirect ( ๐Ÿ› redirect_form_node_form_alter calls getInternalPath on potentially unrouted url Needs review ) and finally (hopefully finally) within Pathauto. The problem in Pathauto appears when one tries to delete a node (or other entity) that has an external canonical url. Upon doing so I get an exception:

Drupal\Core\Entity\EntityStorageException: Unrouted URIs do not have internal representations. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->delete() (line 761 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

Drupal\pathauto\AliasStorageHelper->deleteEntityPathAll(Object) (Line: 101)
pathauto_entity_delete(Object)

Steps to reproduce

See above

Proposed resolution

Add a check could be added to the already long list of checks in pathauto_entity_delete to see if the url is routed.

Alternative the check could be added to AliasStorageHelper::deleteEntityPathAll.

Remaining tasks

User interface changes

N/A

API changes

N/A

Data model changes

N/A

๐Ÿ› Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States danflanagan8 St. Louis, US

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024