- Issue created by @rupertj
- 🇬🇧United Kingdom rupertj Bristol, UK
I've pushed my code to the issue fork, but I'm starting to think it could be overkill, so I'm keen to hear what people think.
It's based on what localgov_directories does. It implements hook_pathauto_pattern_alter() to add the channel URL to an entry URL if the entry is in a channel. The thing is, with finders, the content types set up as entries have to be in a channel, so we don't need to do this exactly like directories.
I've also tried out just setting the pathauto patterns appropriately, and that works.
EG, we could set up localgov_events like this:- Event channel: /events/[node:title]
- Event: [node:finders_channels:0:entity:url:relative]/[node:title]
Letting localgov_events set those patterns and freeing finders from the responsibility of doing anything with URL aliases could be an option.
Either option requires this patch to token to let it use bundle fields: https://www.drupal.org/files/issues/2024-06-27/token-consistent-entity-a... →
- 🇬🇧United Kingdom joachim
> Letting localgov_events set those patterns and freeing finders from the responsibility of doing anything with URL aliases could be an option.
I'm not sure about whether Finders should take care of this. I think I said it github that it should, but I'm wondering whether that's too opinionated for Finders.
We could work around the core patch problem and also improve DX (and UX if we go down the route of users setting it up themselves) by providing our own token for 'node:finders_channels:0:entity'.
Aside:
$bundle_id = $entity->bundle(); $bundle_entity_type_id = $entity->getEntityType()->getBundleEntityType(); $bundle_entity = $this->entityTypeManager->getStorage($bundle_entity_type_id)->load($bundle_id); /** @var ?\Drupal\finders\Entity\FinderInterface $finder */ $finder = $this->entityTypeManager->getStorage('finder')->getFinderForBundleEntity($bundle_entity);
Maybe we need a helper to do all of that? Not sure where I'd put it though.
> The thing is, with finders, the content types set up as entries have to be in a channel, so we don't need to do this exactly like directories.
Is the channel field optional in Directories? Should we have done that in Finders too?
- 🇬🇧United Kingdom joachim
I've thought about it some more, and here's what I think we should do:
- add the channel entity token so we don't need the core patch
- implement the hook like in your MR, but have it hand over to the finder plugin. That way:
-- particular finder plugins can override it if necessary
-- if someone really wants it to be optional, they can either hack it out in a custom plugin, or add a setting for it in the finder config entity