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 (#3342398: Path module calls getInternalPath without checking if the url is routed) and Redirect (#3342409: redirect_form_node_form_alter calls getInternalPath on potentially unrouted url) 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
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | pathauto-unrouted-3357928-2.patch | 860 bytes | danflanagan8 |
Issue fork pathauto-3357928
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
Comment #2
danflanagan8Comment #3
danflanagan8Comment #6
keshavv commentedReview and tested the patch. Confirmed its working good.
Created the MR for the same. +1 for RTBC.
Comment #7
danflanagan8> Confirmed its working good.
Could you elaborate? I don't think that's satisfactory review.
Comment #8
danflanagan8This also needs tests. The tests I wrote for #3342398: Path module calls getInternalPath without checking if the url is routed will be a good place to start. There's an entity in core called `entity_test_external` that is useful for something like this. It's possible though that the core bug will block testing for the pathauto bug. There's a good chance core will throw an exception before pathauto has a chance to.
Comment #9
dpiThanks for the patch, just what I needed.
Comment #11
mably commentedComment #12
mably commentedThis is most probably a duplicate of this related issue.
Comment #13
mably commented