From 87a7b4139e6b98eca66165843681ff0253a6d38b Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Tue, 26 Jun 2012 15:07:46 -0400
Subject: [PATCH] When a variable is injected by the VuFind\Bootstrap process,
 it is only available to the layout; this revision modifies templates to
 access variables through the layout() helper so the correct values are
 accessible everywhere.

---
 .../RecordDriver/SolrDefault/tab-holdings.phtml     |  2 +-
 themes/vufind/blueprint/templates/header.phtml      | 13 +++++++------
 .../templates/myresearch/bulk-action-buttons.phtml  |  2 +-
 .../blueprint/templates/myresearch/login.phtml      |  9 +++++----
 .../blueprint/templates/myresearch/mylist.phtml     |  9 ++++++---
 .../RecordDriver/SolrDefault/tab-holdings.phtml     |  2 +-
 .../templates/default-footer-navbar.phtml           |  5 +++--
 .../templates/myresearch/footer-navbar.phtml        |  2 +-
 .../jquerymobile/templates/myresearch/login.phtml   |  9 +++++----
 9 files changed, 30 insertions(+), 23 deletions(-)

diff --git a/themes/vufind/blueprint/templates/RecordDriver/SolrDefault/tab-holdings.phtml b/themes/vufind/blueprint/templates/RecordDriver/SolrDefault/tab-holdings.phtml
index f1e2c1796b9..53cd96e39f7 100644
--- a/themes/vufind/blueprint/templates/RecordDriver/SolrDefault/tab-holdings.phtml
+++ b/themes/vufind/blueprint/templates/RecordDriver/SolrDefault/tab-holdings.phtml
@@ -20,7 +20,7 @@
   </div>
 <? endif; ?>
 <? if ((VF_ILS_Connection::getHoldsMode() == 'driver' && !empty($holdings)) || VF_ILS_Connection::getTitleHoldsMode() == 'driver'): ?>
-  <? if ($this->account->loginEnabled() && $offlineMode != 'ils-offline'): ?>
+  <? if ($this->layout()->account->loginEnabled() && $offlineMode != 'ils-offline'): ?>
     <? if (!$user): ?>
       <div class="info">
         <a href="<?=$this->serverUrl()?>?login=true&catalogLogin=true"><?=$this->transEsc("Login")?></a> <?=$this->transEsc("hold_login")?>
diff --git a/themes/vufind/blueprint/templates/header.phtml b/themes/vufind/blueprint/templates/header.phtml
index 5290efe75a1..ca603a830c8 100644
--- a/themes/vufind/blueprint/templates/header.phtml
+++ b/themes/vufind/blueprint/templates/header.phtml
@@ -1,3 +1,4 @@
+<? $account = $this->layout()->account; ?>
 <a id="logo" href="<?=$this->url('home')?>"></a>
 <div id="headerRight">
   <? $cart = \VuFind\Cart::getInstance(); if ($cart->isActive()): ?>
@@ -6,24 +7,24 @@
       <a id="viewCart" title="<?=$this->transEsc('View Book Bag')?>" class="viewCart bookbag offscreen" href="<?=$this->url('cart-home')?>"><strong><span id="cartSize"><?=count($cart->getItems())?></span></strong> <?=$this->transEsc('items')?><span id="cartStatus"><?=$cart->isFull() ? $this->transEsc('bookbag_full') : '&nbsp;'?></span></a>
     </div>
   <? endif; ?>
-  <? if (is_object($this->account) && $this->account->loginEnabled()): // hide login/logout if unavailable ?>
-    <div id="logoutOptions"<?=!$this->account->isLoggedIn() ? ' class="hide"' : ''?>>
+  <? if (is_object($account) && $account->loginEnabled()): // hide login/logout if unavailable ?>
+    <div id="logoutOptions"<?=!$account->isLoggedIn() ? ' class="hide"' : ''?>>
       <a class="account" href="<?=$this->url('myresearch-home')?>"><?=$this->transEsc("Your Account")?></a> |
       <a class="logout" href="<?=$this->url('myresearch-logout')?>"><?=$this->transEsc("Log Out")?></a>
     </div>
-    <div id="loginOptions"<?=$this->account->isLoggedIn() ? ' class="hide"' : ''?>>
-    <? if ($sessionInitiator = $this->account->getSessionInitiator()): ?>
+    <div id="loginOptions"<?=$account->isLoggedIn() ? ' class="hide"' : ''?>>
+    <? if ($sessionInitiator = $account->getSessionInitiator()): ?>
       <a class="login" href="<?=$this->escape($sessionInitiator)?>"><?=$this->transEsc("Institutional Login")?></a>
     <? else: ?>
       <a class="login" href="<?=$this->url('myresearch-home')?>"><?=$this->transEsc("Login")?></a>
     <? endif; ?>
     </div>
   <? endif; ?>
-  <? if (isset($this->themeOptions) && count($this->themeOptions) > 1): ?>
+  <? if (isset($this->layout()->themeOptions) && count($this->layout()->themeOptions) > 1): ?>
   <form method="post" name="themeForm" action="" id="themeForm">
     <label for="themeForm_ui"><?=$this->transEsc("Theme")?>:</label>
     <select id="themeForm_ui" name="ui" class="jumpMenu">
-    <? foreach ($this->themeOptions as $current): ?>
+    <? foreach ($this->layout()->themeOptions as $current): ?>
       <option value="<?=$this->escape($current['name'])?>"<?=$current['selected'] ? ' selected="selected"' : ''?>><?=$this->transEsc($current['desc'])?></option>
     <? endforeach; ?>
     </select>
diff --git a/themes/vufind/blueprint/templates/myresearch/bulk-action-buttons.phtml b/themes/vufind/blueprint/templates/myresearch/bulk-action-buttons.phtml
index 2327326be42..a246154c8a9 100644
--- a/themes/vufind/blueprint/templates/myresearch/bulk-action-buttons.phtml
+++ b/themes/vufind/blueprint/templates/myresearch/bulk-action-buttons.phtml
@@ -3,7 +3,7 @@
   <span class="floatleft">|</span>
   <span class="floatleft"><strong><?=$this->transEsc('with_selected')?>: </strong></span>
   <input type="submit" class="mail floatleft button" name="email" value="<?=$this->transEsc('Email')?>" title="<?=$this->transEsc('email_selected')?>"/>
-  <? if ((!is_null($this->list) && $this->list->editAllowed()) || is_null($this->list) && $this->account->isLoggedIn()): ?>
+  <? if ((!is_null($this->list) && $this->list->editAllowed()) || is_null($this->list) && $this->layout()->account->isLoggedIn()): ?>
     <input id="<?=$this->idPrefix?>delete_list_items_<?=!is_null($this->list) ? $this->escape($this->list->id) : ''?>" type="submit" class="delete floatleft button" name="delete" value="<?=$this->transEsc('Delete')?>" title="<?=$this->transEsc('delete_selected')?>"/>
   <? endif; ?>
   <? $exportOptions = VF_Export::getBulkOptions(); if (count($exportOptions) > 0): ?>
diff --git a/themes/vufind/blueprint/templates/myresearch/login.phtml b/themes/vufind/blueprint/templates/myresearch/login.phtml
index c841ece95d3..0efadba9063 100644
--- a/themes/vufind/blueprint/templates/myresearch/login.phtml
+++ b/themes/vufind/blueprint/templates/myresearch/login.phtml
@@ -13,7 +13,8 @@
     }
 
     // Convenience variables:
-    $hideLogin = !(is_object($this->account) && $this->account->loginEnabled());
+    $account = $this->layout()->account;
+    $hideLogin = !(is_object($account) && $account->loginEnabled());
     $offlineMode = VF_Connection_Manager::connectToCatalog()->getOfflineMode();
 ?>
 
@@ -33,7 +34,7 @@
 <? if ($hideLogin): ?>
   <div class="error"><?=$this->transEsc('login_disabled')?></div>
 <? else: ?>
-  <? if (!$this->account->getSessionInitiator()): // display default login form if no login URL provided ?>
+  <? if (!$account->getSessionInitiator()): // display default login form if no login URL provided ?>
     <form method="post" action="<?=$this->url('myresearch-home')?>" name="loginForm" id="loginForm">
       <?=$this->auth()->getLoginFields()?>
       <input class="push-2 button" type="submit" name="processLogin" value="<?=$this->transEsc('Login')?>"/>
@@ -44,10 +45,10 @@
       $initJs = '$(document).ready(function() { $(\'#loginForm\').validate(); });';
       echo $this->inlineScript(Zend_View_Helper_HeadScript::SCRIPT, $initJs);
     ?>
-    <? if ($this->account->supportsCreation()): ?>
+    <? if ($account->supportsCreation()): ?>
       <a class="new_account" href="<?=$this->url('myresearch-account')?>"><?=$this->transEsc('Create New Account')?></a>
     <? endif; ?>
   <? else: ?>
-    <a href="<?=$this->escape($this->account->getSessionInitiator())?>"><?=$this->transEsc("Institutional Login")?></a>
+    <a href="<?=$this->escape($account->getSessionInitiator())?>"><?=$this->transEsc("Institutional Login")?></a>
   <? endif; ?>
 <? endif; ?>
\ No newline at end of file
diff --git a/themes/vufind/blueprint/templates/myresearch/mylist.phtml b/themes/vufind/blueprint/templates/myresearch/mylist.phtml
index 0bbe06004ff..4cf1b7b9399 100644
--- a/themes/vufind/blueprint/templates/myresearch/mylist.phtml
+++ b/themes/vufind/blueprint/templates/myresearch/mylist.phtml
@@ -13,6 +13,9 @@
 
     // Load Javascript dependencies into header:
     $this->headScript()->appendFile("bulk_actions.js");
+
+    // Convenience variable:
+    $account = $this->layout()->account;
 ?>
 
 <?=$this->flashmessages()?>
@@ -48,16 +51,16 @@
         <input type="hidden" name="listID" value="<?=$this->escape($list->id)?>" />
         <input type="hidden" name="listName" value="<?=$this->escape($list->title)?>" />
       <? endif; ?>
-      <?=$this->context($this)->renderInContext('myresearch/bulk-action-buttons.phtml', array('idPrefix' => '', 'list' => isset($list) ? $list : null, 'account' => $this->account))?>
+      <?=$this->context($this)->renderInContext('myresearch/bulk-action-buttons.phtml', array('idPrefix' => '', 'list' => isset($list) ? $list : null))?>
       <ul class="recordSet">
         <? $i = 0; foreach ($this->results->getResults() as $current): ?>
           <li class="result<?=(++$i % 2 == 0) ? ' alt' : ''?>">
             <span class="recordNumber"><?=$this->results->getStartRecord()+$i-1?><?=$this->record($current)->getCheckbox()?></span>
-            <?=$this->record($current)->getListEntry($list, $this->account->isLoggedIn())?>
+            <?=$this->record($current)->getListEntry($list, $account->isLoggedIn())?>
           </li>
         <? endforeach; ?>
       </ul>
-      <?=$this->context($this)->renderInContext('myresearch/bulk-action-buttons.phtml', array('idPrefix' => 'bottom_', 'list' => isset($list) ? $list : null, 'account' => $this->account))?>
+      <?=$this->context($this)->renderInContext('myresearch/bulk-action-buttons.phtml', array('idPrefix' => 'bottom_', 'list' => isset($list) ? $list : null))?>
     </form>
     <?=$this->paginationControl($this->results->getPaginator(), 'Sliding', 'search/pagination.phtml', array('results' => $this->results))?>
   <? else: ?>
diff --git a/themes/vufind/jquerymobile/templates/RecordDriver/SolrDefault/tab-holdings.phtml b/themes/vufind/jquerymobile/templates/RecordDriver/SolrDefault/tab-holdings.phtml
index 9af7b5eb999..f243908d4ae 100644
--- a/themes/vufind/jquerymobile/templates/RecordDriver/SolrDefault/tab-holdings.phtml
+++ b/themes/vufind/jquerymobile/templates/RecordDriver/SolrDefault/tab-holdings.phtml
@@ -20,7 +20,7 @@
   </div>
 <? endif; ?>
 <? if ((VF_ILS_Connection::getHoldsMode() == 'driver' && !empty($holdings)) || VF_ILS_Connection::getTitleHoldsMode() == 'driver'): ?>
-  <? if ($this->account->loginEnabled() && $offlineMode != 'ils-offline'): ?>
+  <? if ($this->layout()->account->loginEnabled() && $offlineMode != 'ils-offline'): ?>
     <? if (!$user): ?>
       <div class="info">
         <a href="<?=$this->serverUrl()?>?login=true&catalogLogin=true"><?=$this->transEsc("Login")?></a> <?=$this->transEsc("hold_login")?>
diff --git a/themes/vufind/jquerymobile/templates/default-footer-navbar.phtml b/themes/vufind/jquerymobile/templates/default-footer-navbar.phtml
index d39f4a356ff..7637a414779 100644
--- a/themes/vufind/jquerymobile/templates/default-footer-navbar.phtml
+++ b/themes/vufind/jquerymobile/templates/default-footer-navbar.phtml
@@ -1,10 +1,11 @@
+<? $account = $this->layout()->account; ?>
 <div data-role="navbar">
   <ul>
     <li><a data-rel="dialog" href="#Language-dialog" data-transition="pop"><?=$this->transEsc('Language')?></a></li>
-    <? if (is_object($this->account) && $this->account->loginEnabled()): // hide login/logout if unavailable ?>
+    <? if (is_object($account) && $account->loginEnabled()): // hide login/logout if unavailable ?>
       <li><a rel="external" href="<?=$this->url('myresearch-home')?>"><?=$this->transEsc('Account')?></a></li>
     <? endif; ?>
-    <? if (is_object($this->account) && $this->account->isLoggedIn()): ?>
+    <? if (is_object($account) && $account->isLoggedIn()): ?>
       <li><a rel="external" href="<?=$this->url('myresearch-logout')?>"><?=$this->transEsc("Log Out")?></a></li>
     <? endif; ?>
   </ul>
diff --git a/themes/vufind/jquerymobile/templates/myresearch/footer-navbar.phtml b/themes/vufind/jquerymobile/templates/myresearch/footer-navbar.phtml
index 0e1b7a80f19..5de39491f9e 100644
--- a/themes/vufind/jquerymobile/templates/myresearch/footer-navbar.phtml
+++ b/themes/vufind/jquerymobile/templates/myresearch/footer-navbar.phtml
@@ -1,4 +1,4 @@
-<? if ($this->account->isLoggedIn()): ?>
+<? if ($this->layout()->account->isLoggedIn()): ?>
   <div data-role="navbar">
     <ul>
       <li><a rel="external" <?=$this->action=="mylist" ? ' class="ui-btn-active"' : ''?> href="<?=$this->url('myresearch-favorites')?>"><?=$this->transEsc('Favorites')?></a></li>
diff --git a/themes/vufind/jquerymobile/templates/myresearch/login.phtml b/themes/vufind/jquerymobile/templates/myresearch/login.phtml
index b4be6532380..2be28f8952e 100644
--- a/themes/vufind/jquerymobile/templates/myresearch/login.phtml
+++ b/themes/vufind/jquerymobile/templates/myresearch/login.phtml
@@ -3,7 +3,8 @@
     $this->headTitle($this->translate('Login'));
 
     // Convenience variables:
-    $hideLogin = !(is_object($this->account) && $this->account->loginEnabled());
+    $account = $this->layout()->account;
+    $hideLogin = !(is_object($account) && $account->loginEnabled());
     $offlineMode = VF_Connection_Manager::connectToCatalog()->getOfflineMode();
 ?>
 <div data-role="page" id="MyResearch-login">
@@ -24,7 +25,7 @@
     <? if (!$hideLogin): ?>
       <h3><?=$this->transEsc('Login')?></h3>
       <?=$this->flashmessages()?>
-      <? if (!$this->account->getSessionInitiator()): // display default login form if no login URL provided ?>
+      <? if (!$account->getSessionInitiator()): // display default login form if no login URL provided ?>
         <form method="post" action="<?=$this->url('myresearch-home')?>" name="loginForm" data-ajax="false">
           <div data-role="fieldcontain">
             <?=$this->auth()->getLoginFields()?>
@@ -33,11 +34,11 @@
             <input type="submit" name="processLogin" value="<?=$this->transEsc('Login')?>"/>
           </div>
         </form>
-        <? if ($this->account->supportsCreation()): ?>
+        <? if ($account->supportsCreation()): ?>
           <a rel="external" data-role="button" class="new_account" href="<?=$this->url('myresearch-account')?>"><?=$this->transEsc('Create New Account')?></a>
         <? endif; ?>
       <? else: ?>
-        <a rel="external" data-role="button" href="<?=$this->escape($this->account->getSessionInitiator())?>"><?=$this->transEsc("Institutional Login")?></a>
+        <a rel="external" data-role="button" href="<?=$this->escape($account->getSessionInitiator())?>"><?=$this->transEsc("Institutional Login")?></a>
       <? endif; ?>
     <? endif; ?>
   </div>
-- 
GitLab