From 0172fff0a4eb736b5db5c4df1e1bcdd6322ed148 Mon Sep 17 00:00:00 2001
From: Chris Hallberg <crhallberg@gmail.com>
Date: Mon, 11 May 2020 10:01:15 -0400
Subject: [PATCH] Add Print button to record toolbar (#1507)

---
 .../src/VuFindTest/Mink/RecordActionsTest.php | 22 ++++++
 .../RecordDriver/DefaultRecord/toolbar.phtml  | 72 ++++++++++---------
 2 files changed, 61 insertions(+), 33 deletions(-)

diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/RecordActionsTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/RecordActionsTest.php
index dca04a80d83..d2d1178a223 100644
--- a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/RecordActionsTest.php
+++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/RecordActionsTest.php
@@ -428,6 +428,28 @@ class RecordActionsTest extends \VuFindTest\Unit\MinkTestCase
         $this->findCss($page, '.modal .alert-success');
     }
 
+    /**
+     * Test record view print button.
+     */
+    public function testPrint(): void
+    {
+        // Go to a record view (manually search so we can access $session)
+        $session = $this->getMinkSession();
+        $session->visit($this->getVuFindUrl() . '/Search/Home');
+        $page = $session->getPage();
+        $this->findCss($page, '#searchForm_lookfor')->setValue('Dewey');
+        $this->findCss($page, '.btn.btn-primary')->click();
+        $this->clickCss($page, '.result a.title');
+
+        // Click Print
+        $this->clickCss($page, '.print-record');
+        $this->snooze();
+
+        // Make sure we're printing
+        list(, $params) = explode('?', $session->getCurrentUrl());
+        $this->assertEquals('print=1', $params);
+    }
+
     /**
      * Retry cleanup method in case of failure during testAddTag.
      *
diff --git a/themes/bootstrap3/templates/RecordDriver/DefaultRecord/toolbar.phtml b/themes/bootstrap3/templates/RecordDriver/DefaultRecord/toolbar.phtml
index daaea74f87e..acdeed3b821 100644
--- a/themes/bootstrap3/templates/RecordDriver/DefaultRecord/toolbar.phtml
+++ b/themes/bootstrap3/templates/RecordDriver/DefaultRecord/toolbar.phtml
@@ -4,38 +4,44 @@
     $this->headScript()->appendFile('https://s7.addthis.com/js/250/addthis_widget.js?pub=' . urlencode($addThis));
   }
 ?>
-<ul class="record-nav nav nav-pills hidden-print">
-  <?php if (count($this->driver->getCitationFormats()) > 0): ?>
-    <li><a class="cite-record" data-lightbox href="<?=$this->recordLink()->getActionUrl($this->driver, 'Cite')?>" rel="nofollow"><i class="fa fa-asterisk" aria-hidden="true"></i> <?=$this->transEsc('Cite this')?></a></li>
-  <?php endif; ?>
-  <?php if ($this->accountCapabilities()->getSmsSetting() !== 'disabled'): ?>
-    <li><a class="sms-record" data-lightbox href="<?=$this->recordLink()->getActionUrl($this->driver, 'SMS')?>" rel="nofollow"><i class="fa fa-mobile" aria-hidden="true"></i> <?=$this->transEsc('Text this')?></a></li>
-  <?php endif; ?>
-  <li><a class="mail-record" data-lightbox href="<?=$this->recordLink()->getActionUrl($this->driver, 'Email')?>" rel="nofollow"><i class="fa fa-envelope" aria-hidden="true"></i> <?=$this->transEsc('Email this')?></a></li>
+<nav class="record-nav">
+  <ul class="action-toolbar">
+    <?php if (count($this->driver->getCitationFormats()) > 0): ?>
+      <li><a class="cite-record toolbar-btn btn-type-cite" data-lightbox href="<?=$this->recordLink()->getActionUrl($this->driver, 'Cite')?>" rel="nofollow"><?=$this->transEsc('Cite this')?></a></li>
+    <?php endif; ?>
 
-  <?php $exportFormats = $this->export()->getFormatsForRecord($this->driver); ?>
-  <?php if(count($exportFormats) > 0): ?>
-    <li class="dropdown">
-      <a class="export-toggle dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" href="<?=$this->recordLink()->getActionUrl($this->driver, 'Export')?>" rel="nofollow"><i class="fa fa-list-alt" aria-hidden="true"></i> <?=$this->transEsc('Export Record') ?></a>
-      <ul class="dropdown-menu" role="menu">
-        <?php foreach ($exportFormats as $exportFormat): ?>
-          <li role="none"><a <?php if ($this->export()->needsRedirect($exportFormat)): ?>target="<?=$this->escapeHtmlAttr($exportFormat)?>Main" <?php endif; ?>href="<?=$this->recordLink()->getActionUrl($this->driver, 'Export')?>?style=<?=$this->escapeHtmlAttr($exportFormat)?>" rel="nofollow" role="menuitem"><?=$this->transEsc('Export to')?> <?=$this->transEsc($this->export()->getLabelForFormat($exportFormat))?></a></li>
-        <?php endforeach; ?>
-      </ul>
-    </li>
-  <?php endif; ?>
+    <?php if ($this->accountCapabilities()->getSmsSetting() !== 'disabled'): ?>
+      <li><a class="sms-record toolbar-btn btn-type-phone" data-lightbox href="<?=$this->recordLink()->getActionUrl($this->driver, 'SMS')?>" rel="nofollow"><?=$this->transEsc('Text this')?></a></li>
+    <?php endif; ?>
 
-  <?php if ($this->userlist()->getMode() !== 'disabled'): ?>
-    <li>
-      <?php if ($this->permission()->allowDisplay('feature.Favorites')): ?>
-        <a class="save-record" data-lightbox href="<?=$this->recordLink()->getActionUrl($this->driver, 'Save')?>" rel="nofollow"><i class="fa fa-star" aria-hidden="true"></i> <?=$this->transEsc('Add to favorites')?></a>
-      <?php elseif ($block = $this->permission()->getAlternateContent('feature.Favorites')): ?>
-        <?=$block?>
-      <?php endif; ?>
-    </li>
-  <?php endif; ?>
-  <?php if (!empty($addThis)): ?>
-    <li><a class="addThis addthis_button" href="https://www.addthis.com/bookmark.php?v=250&amp;pub=<?=urlencode($addThis)?>"><i class="fa fa-bookmark" aria-hidden="true"></i> <?=$this->transEsc('Bookmark')?></a></li>
-  <?php endif; ?>
-  <?=$this->render('record/cart-buttons.phtml', ['id' => $this->driver->getUniqueId(), 'source' => $this->driver->getSourceIdentifier()]); ?>
-</ul>
+    <li><a class="mail-record toolbar-btn btn-type-email" data-lightbox href="<?=$this->recordLink()->getActionUrl($this->driver, 'Email')?>" rel="nofollow"><?=$this->transEsc('Email this')?></a></li>
+
+    <li><a class="print-record toolbar-btn btn-type-print" href="<?=$this->url()->addQueryParameters(['print' => true])?>" rel="nofollow"><?=$this->transEsc('Print')?></a></li>
+
+    <?php $exportFormats = $this->export()->getFormatsForRecord($this->driver); ?>
+    <?php if(count($exportFormats) > 0): ?>
+      <li class="dropdown">
+        <a class="export-toggle toolbar-btn btn-type-export dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" href="<?=$this->recordLink()->getActionUrl($this->driver, 'Export')?>" rel="nofollow"><?=$this->transEsc('Export Record') ?></a>
+        <ul class="dropdown-menu" role="menu">
+          <?php foreach ($exportFormats as $exportFormat): ?>
+            <li role="none"><a <?php if ($this->export()->needsRedirect($exportFormat)): ?>target="<?=$this->escapeHtmlAttr($exportFormat)?>Main" <?php endif; ?>href="<?=$this->recordLink()->getActionUrl($this->driver, 'Export')?>?style=<?=$this->escapeHtmlAttr($exportFormat)?>" rel="nofollow" role="menuitem"><?=$this->transEsc('Export to')?> <?=$this->transEsc($this->export()->getLabelForFormat($exportFormat))?></a></li>
+          <?php endforeach; ?>
+        </ul>
+      </li>
+    <?php endif; ?>
+
+    <?php if ($this->userlist()->getMode() !== 'disabled'): ?>
+      <li>
+        <?php if ($this->permission()->allowDisplay('feature.Favorites')): ?>
+          <a class="save-record toolbar-btn btn-type-save" data-lightbox href="<?=$this->recordLink()->getActionUrl($this->driver, 'Save')?>" rel="nofollow"><?=$this->transEsc('Add to favorites')?></a>
+        <?php elseif ($block = $this->permission()->getAlternateContent('feature.Favorites')): ?>
+          <?=$block?>
+        <?php endif; ?>
+      </li>
+    <?php endif; ?>
+    <?php if (!empty($addThis)): ?>
+      <li><a class="addThis addthis_button" href="https://www.addthis.com/bookmark.php?v=250&amp;pub=<?=urlencode($addThis)?>"><i class="fa fa-bookmark" aria-hidden="true"></i> <?=$this->transEsc('Bookmark')?></a></li>
+    <?php endif; ?>
+    <?=$this->render('record/cart-buttons.phtml', ['id' => $this->driver->getUniqueId(), 'source' => $this->driver->getSourceIdentifier()]); ?>
+  </ul>
+</nav>
-- 
GitLab