From 5281f36ee8f99da9c9d269a500181ba28de90f7f Mon Sep 17 00:00:00 2001
From: Oliver Goldschmidt <o.goldschmidt@tu-harburg.de>
Date: Wed, 7 Sep 2016 15:30:59 +0200
Subject: [PATCH] Allow ILS driver to provide up-front cancel details (#740)

---
 .../src/VuFind/Controller/Plugin/Holds.php      | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/module/VuFind/src/VuFind/Controller/Plugin/Holds.php b/module/VuFind/src/VuFind/Controller/Plugin/Holds.php
index ba68d708f80..b8ce7380ec0 100644
--- a/module/VuFind/src/VuFind/Controller/Plugin/Holds.php
+++ b/module/VuFind/src/VuFind/Controller/Plugin/Holds.php
@@ -58,14 +58,29 @@ class Holds extends AbstractRequestBase
                 // Build OPAC URL
                 $ilsDetails['cancel_link']
                     = $catalog->getCancelHoldLink($ilsDetails);
+            } else if (isset($ilsDetails['cancel_details'])) {
+                // The ILS driver provided cancel details up front. If the
+                // details are an empty string (flagging lack of support), we
+                // should unset it to prevent confusion; otherwise, we'll leave it
+                // as-is.
+                if ('' === $ilsDetails['cancel_details']) {
+                    unset($ilsDetails['cancel_details']);
+                } else {
+                    $this->rememberValidId($ilsDetails['cancel_details']);
+                }
             } else {
-                // Form Details
+                // Default case: ILS supports cancel but we need to look up
+                // details:
                 $cancelDetails = $catalog->getCancelHoldDetails($ilsDetails);
                 if ($cancelDetails !== '') {
                     $ilsDetails['cancel_details'] = $cancelDetails;
                     $this->rememberValidId($ilsDetails['cancel_details']);
                 }
             }
+        } else {
+            // Cancelling holds disabled? Make sure no details get passed back:
+            unset($ilsDetails['cancel_link']);
+            unset($ilsDetails['cancel_details']);
         }
 
         return $ilsDetails;
-- 
GitLab