From 54c0341a4012967ebe3cec174e5ff9e8c638e8c2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Samuli=20Sillanp=C3=A4=C3=A4?=
 <samuli.sillanpaa@helsinki.fi>
Date: Wed, 21 Aug 2019 21:19:13 +0300
Subject: [PATCH] Add support for displaying feedback form in lightbox. (#1405)

- Includes centralization/standardization of lightbox detection logic.
---
 .../src/VuFind/Controller/AbstractBase.php    | 19 ++++++++++++++++---
 .../Controller/MyResearchController.php       | 11 -----------
 .../bootstrap3/templates/feedback/form.phtml  |  7 ++++---
 3 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/module/VuFind/src/VuFind/Controller/AbstractBase.php b/module/VuFind/src/VuFind/Controller/AbstractBase.php
index c7024ba7d54..69fdaf2c5c7 100644
--- a/module/VuFind/src/VuFind/Controller/AbstractBase.php
+++ b/module/VuFind/src/VuFind/Controller/AbstractBase.php
@@ -132,10 +132,9 @@ class AbstractBase extends AbstractActionController
      */
     protected function createViewModel($params = null)
     {
-        $layout = $this->params()
-            ->fromPost('layout', $this->params()->fromQuery('layout', false));
-        if ('lightbox' === $layout) {
+        if ($this->inLightbox()) {
             $this->layout()->setTemplate('layout/lightbox');
+            $params['inLightbox'] = true;
         }
         return new ViewModel($params);
     }
@@ -679,4 +678,18 @@ class AbstractBase extends AbstractActionController
     {
         return $this->serviceLocator->get(\VuFind\RecordTab\TabManager::class);
     }
+
+    /**
+     * Are we currently in a lightbox context?
+     *
+     * @return bool
+     */
+    protected function inLightbox()
+    {
+        return
+            $this->params()->fromPost(
+                'layout', $this->params()->fromQuery('layout', false)
+            ) === 'lightbox'
+            || 'layout/lightbox' == $this->layout()->getTemplate();
+    }
 }
diff --git a/module/VuFind/src/VuFind/Controller/MyResearchController.php b/module/VuFind/src/VuFind/Controller/MyResearchController.php
index 0dc721062eb..0c3dcad453d 100644
--- a/module/VuFind/src/VuFind/Controller/MyResearchController.php
+++ b/module/VuFind/src/VuFind/Controller/MyResearchController.php
@@ -56,17 +56,6 @@ class MyResearchController extends AbstractBase
      */
     protected $paginationHelper = null;
 
-    /**
-     * Are we currently in a lightbox context?
-     *
-     * @return bool
-     */
-    protected function inLightbox()
-    {
-        return $this->getRequest()->getQuery('layout', 'no') === 'lightbox'
-            || 'layout/lightbox' == $this->layout()->getTemplate();
-    }
-
     /**
      * Construct an HTTP 205 (refresh) response. Useful for reporting success
      * in the lightbox without actually rendering content.
diff --git a/themes/bootstrap3/templates/feedback/form.phtml b/themes/bootstrap3/templates/feedback/form.phtml
index 1b4802c0fd3..5f427435539 100644
--- a/themes/bootstrap3/templates/feedback/form.phtml
+++ b/themes/bootstrap3/templates/feedback/form.phtml
@@ -16,10 +16,11 @@
   $helpPre = isset($help['pre']) ? $this->translate($help['pre']) : null;
   $helpPost = isset($help['post']) ? $this->translate($help['post']) : null;
 ?>
-<div class="feedback-content">
+<?php if (!$this->inLightbox): ?><div class="feedback-content"><?php endif; ?>
   <?php if ($title): ?>
     <?php $this->headTitle($title); ?>
-    <h1><?=$title?></h1>
+    <?php $headTag = $this->inLightbox ? 'h2' : 'h1'; ?>
+    <<?=$headTag?>><?=$title?></<?=$headTag?>>
   <?php endif; ?>
   <?=$this->flashmessages()?>
 
@@ -96,4 +97,4 @@
   <?php endforeach ?>
   <?= $this->form()->closeTag() ?>
   <?php endif ?>
-</div>
+<?php if (!$this->inLightbox): ?></div><?php endif; ?>
-- 
GitLab