- Issue created by @danflanagan8
- πΊπΈUnited States bvoynick
Thank you for the report & suggestion to override hasLinkTemplate, it's coming in handy for me today.
I'm using a bundle class to override the toUrl() method on a particular node type. If some condition is met (the specifics are not important) I don't want the node to be visible on its own page and I don't want teasers and cards to render any links to the node
public function toUrl($rel = 'canonical', array $options = []) {
if ($rel === 'canonical') {
if (//some condition) {
return Url::fromRoute('<nolink>');
}
}
return parent::toUrl($rel, $options);
}
Let's assume I have created a node that meets the condition to have <nolink>
as its canonical url. If I delete that node, every single url alias gets deleted.
That's because AliasStorageHelperInterface::deleteBySourcePrefix()
gets called with /
as the prefiz, which of course matches all aliases.
Add some check somewhere to prevent accidentally deleting all url aliases if a canonical url is <nolink>
. Not sure if that would be best in AliasStorageHelper or pathauto.module.
One way to prevent this mass deletion from happening is to override the hasLinkTemplate()
method in the bundle class such that it returns false if the node has a canonical url.
/**
* {@inheritdoc}
*/
public function hasLinkTemplate($rel) {
if ($rel === 'canonical') {
if (//some condition) {
return FALSE;
}
}
return parent::hasLinkTemplate($rel);
}
Active
1.0
Code
Thank you for the report & suggestion to override hasLinkTemplate, it's coming in handy for me today.