Open rupertj opened 5 months ago
So the current logic is that if the SubsiteService doesn't find a subsite homepage for the given node, it checks to see if the given node is a localgov_directories_page. If it is, we get the directory channel from the page and repeat the walk up the menu tree to look for a subsite homepage again.
We could generalise this for other content types by adding a hook (which for the purpose of this discussion we'll call hook_subsites_extra_current_node_alter) before we walk the tree that can swop out the current node for another.
So the logic in the service would be:
Then the directories module (or localgov subsites extra on directories' behalf) implements the hook and does this:
We can then do the same for other types that implement the pattern of having pages assigned to an overview or a channel.
Directory venue needs the same handling as directory pages.
Also
Is it worth pointing out: any content type can be a directory entry. An existing, or new, created by the admin, content type. It only requires the directory reference field to be added to it to work as a directory page. There are already more content types that are directory pages in localgov_directories, there's the fancy pages one, and the organisation one, off the top of my head.
Adds: This is the pattern used for quite a few, if not all, of these. It's not hard coded by content type, but by the existence of the appropriate entity reference field.
@ekes Cheers for that. I'll make it work on the fields then :)
@ekes I've made a PR that does exactly that for directories and guides, as they're the ones that Ben HJ's wanting to add to Dumfries and Galloway's subsites. Care to give it a review? If it's looking good to you I'll use the same technique for the other types.
@rupertj where's the PR - thanks
HI @willguv. It's here: https://github.com/localgovdrupal/localgov_subsites_extras/pull/16
We currently have a special case to let directory pages inherit their subsite placement from the directory channel that they're in. (See SubsiteService::findHomePage()).
H&F have worked around this problem for guide pages - we could handle them automatically too, along with any other content type that that's linked to an overview, channel, etc.
It'd be nice if we did this with a hook or event so other modules could implement their own logic for content types they defined.