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

Broken preview link #102

Open Adnan-cds opened 2 years ago

Adnan-cds commented 2 years ago

Preview link is causing WSOD (White screen of death) for unpublished Subsite overview and Subsite pages. @FinnERLewis @ekes @stephen-cox @MattOz-CDS

How to reproduce

First attempt at a Fix

diff --git a/src/Plugin/Block/SubsitesNavigationBlock.php b/src/Plugin/Block/SubsitesNavigationBlock.php
index 015e6e4..ced2386 100644
--- a/src/Plugin/Block/SubsitesNavigationBlock.php
+++ b/src/Plugin/Block/SubsitesNavigationBlock.php
@@ -56,8 +56,10 @@ class SubsitesNavigationBlock extends SubsitesAbstractBlockBase {
       $mapper = \Drupal::service('entity_hierarchy.entity_tree_node_mapper');
       $entities = $mapper->loadAndAccessCheckEntitysForTreeNodes('node', $tree, $cache);
       $items = $this->nestTree($tree, $ancestors, $entities);
-      $subsite_id = $entities[$ancestors[0]]->id();
-      $overview_entity = $entities[$ancestors[0]];
+
+      $all_entities = $mapper->loadEntitiesForTreeNodesWithoutAccessChecks('node', $tree, $cache);
+      $subsite_id = $all_entities[$ancestors[0]]->id();
+      $overview_entity = $all_entities[$ancestors[0]];
     }
     elseif ($subsite_entity->bundle('localgov_subsites_overview')) {
       // Subsite overview page with no children.
diff --git a/templates/subsite-navigation.html.twig b/templates/subsite-navigation.html.twig
index 1c598cf..704040b 100644
--- a/templates/subsite-navigation.html.twig
+++ b/templates/subsite-navigation.html.twig
@@ -45,12 +45,14 @@
           item.in_active_trail ? 'menu-item--active-trail',
         ]
       %}
+      {% if item.url %}
       <li{{ item.attributes.addClass(classes) }}>
         {{ link(item.title, item.url) }}
         {% if item.below %}
           {{ subsite_navigation.menu_links(item.below, attributes, menu_level + 1) }}
         {% endif %}
       </li>
+      {% endif %}
     {% endfor %}
     </ul>
   {% endif %}