localgovdrupal / localgov_subsites

Replaces LocalGov Campaigns with a new name and extended functionality to support subsites within LocalGov Drupal installations.
GNU General Public License v2.0
4 stars 2 forks source link

Fix PHP error on subsite page when overview is unpublished #121

Closed andybroomfield closed 1 year ago

andybroomfield commented 1 year ago

Fix #118

Set the $subsite_id and $overview_entity to NULL if the overview is unpublished and the user doesn't have access to it. (It's not found in loadAndAccessCheckEntitysForTreeNodes).

This also required a change in the subsite navigation twig to check that the link has a url before attempting to output it, a simmilar change will be needed on any theme that has implemented the template.

Note: The test fails here due to the way the blocks cache.

andybroomfield commented 1 year ago

So an alternative is to use loadEntitiesForTreeNodesWithoutAccessChecks just to look for the parent subsite ID, which is needed to add a cache context. I assume that as the navigation block, there is no real risk in leaking the subsite entity to the template if the overview entity is fetched for cache purposes?

stephen-cox commented 1 year ago

@andybroomfield It's definitely a caching issue, but I have only managed to solve it by adding a drupal_flush_all_caches(); before getting the subsite_page1 contents.

I think this is fine so will push the change.