standalone: move breadcrumb rendering into template
authorRich Lott / Artful Robot <code.commits@artfulrobot.uk>
Thu, 27 Jul 2023 15:03:27 +0000 (16:03 +0100)
committerRich Lott / Artful Robot <code.commits@artfulrobot.uk>
Thu, 27 Jul 2023 15:03:27 +0000 (16:03 +0100)
CRM/Core/Invoke.php
CRM/Utils/System/Standalone.php
templates/CRM/common/standalone.tpl

index 51b2d0cb1502b7e20284efead33defff7fddfc7d..230ceb7c14275baebc6663b9d73fc71e97454fba 100644 (file)
@@ -249,7 +249,7 @@ class CRM_Core_Invoke {
         CRM_Utils_System::setTitle($item['title']);
       }
 
-      if (isset($item['breadcrumb']) && !isset($item['is_public'])) {
+      if (isset($item['breadcrumb']) && empty($item['is_public'])) {
         CRM_Utils_System::appendBreadCrumb($item['breadcrumb']);
       }
 
index 3b33669a01a919dbdb404b7263b229e073c0896a..f560e2456fe2fd4c77768ff31565fbbbd2a9d112 100644 (file)
@@ -108,7 +108,11 @@ class CRM_Utils_System_Standalone extends CRM_Utils_System_Base {
    * @inheritDoc
    */
   public function appendBreadCrumb($breadcrumbs) {
-    \Civi::$statics[__CLASS__]['breadcrumb'][] = $breadcrumbs;
+    if (!isset(\Civi::$statics[__CLASS__]['breadcrumb'])) {
+      \Civi::$statics[__CLASS__]['breadcrumb'] = [];
+    }
+    \Civi::$statics[__CLASS__]['breadcrumb'] += $breadcrumbs;
+    CRM_Core_Smarty::singleton()->assign('breadcrumb', \Civi::$statics[__CLASS__]['breadcrumb']);
   }
 
   /**
@@ -116,6 +120,7 @@ class CRM_Utils_System_Standalone extends CRM_Utils_System_Base {
    */
   public function resetBreadCrumb() {
     \Civi::$statics[__CLASS__]['breadcrumb'] = [];
+    CRM_Core_Smarty::singleton()->assign('breadcrumb', NULL);
   }
 
   /**
@@ -123,6 +128,9 @@ class CRM_Utils_System_Standalone extends CRM_Utils_System_Base {
    */
   public function addHTMLHead($header) {
     $template = CRM_Core_Smarty::singleton();
+    // Smarty's append function does not check for the existence of the var before appending to it.
+    // So this prevents a stupid notice error:
+    $template->ensureVariablesAreAssigned(['pageHTMLHead']);
     $template->append('pageHTMLHead', $header);
     return;
   }
@@ -261,18 +269,6 @@ class CRM_Utils_System_Standalone extends CRM_Utils_System_Base {
       echo implode('', $smarty->_tpl_vars['pageHTMLHead']);
     }
 
-    // Show the breadcrumb
-    if (!empty(\Civi::$statics[__CLASS__]['breadcrumb'])) {
-      print '<nav aria-label="' . htmlspecialchars(ts('Breadcrumb')) . '" class="breadcrumb"><ol>';
-      print '<li><a href="' . CRM_Utils_System::url('civicrm/dashboard', 'reset=1') . '">' . htmlspecialchars(ts('Home')) . '</a></li>';
-      foreach (\Civi::$statics[__CLASS__]['breadcrumb'] as $breadcrumb) {
-        foreach ($breadcrumb as $item) {
-          print '<li><a href="' . $item['url'] . '">' . htmlspecialchars($item['title']) . '</a></li>';
-        }
-      }
-      print '</ol></nav>';
-    }
-
     // @todo Add variables from the body tag? (for Shoreditch)
     print $content;
     return NULL;
index cfff2477595da8e0396f3a08eae9c1f9085cd7ec..154adfa2f8876cc2c4c837fec5dda86896f0d4ac 100644 (file)
   <title>{$docTitle}</title>
 </head>
 <body>
-
   {if $config->debug}
   {include file="CRM/common/debug.tpl"}
   {/if}
 
   <div id="crm-container" class="crm-container" lang="{$config->lcMessages|substr:0:2}" xml:lang="{$config->lcMessages|substr:0:2}">
     {if $breadcrumb}
-      <div class="breadcrumb">
+      <nav aria-label="{ts}Breadcrumb{/ts}" class="breadcrumb"><ol>
+        <li><a href="/civicrm/dashboard?reset=1" >{ts}Home{/ts}</a></li>
         {foreach from=$breadcrumb item=crumb key=key}
-          {if $key != 0}
-            &raquo;
-          {/if}
-          <a href="{$crumb.url}">{$crumb.title}</a>
+          <li><a href="{$crumb.url}">{$crumb.title}</a></li>
         {/foreach}
-      </div>
+      </ol></nav>
     {/if}
 
     {if $pageTitle}