From a9823b0f06c3a41c6ccf83ab4b95b06c738d6115 Mon Sep 17 00:00:00 2001
From: Carsten  Rose <carsten.rose@math.uzh.ch>
Date: Tue, 31 Jan 2017 23:26:13 +0100
Subject: [PATCH] QuickFormQuery.php: Suppress renderinf of form title during a
 'delete' call. No one will see and required parameters are not supplied.

---
 extension/qfq/qfq/Constants.php      |  1 +
 extension/qfq/qfq/QuickFormQuery.php | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/extension/qfq/qfq/Constants.php b/extension/qfq/qfq/Constants.php
index 2e354adf6..30d7ddb85 100644
--- a/extension/qfq/qfq/Constants.php
+++ b/extension/qfq/qfq/Constants.php
@@ -443,6 +443,7 @@ const GLYPH_ICON_CLOSE = 'glyphicon-remove';
 
 // FORM
 const F_NAME = 'name';
+const F_TITLE = 'title';
 const F_TABLE_NAME = 'tableName';
 const F_REQUIRED_PARAMETER = 'requiredParameter';
 const F_EXTRA_DELETE_FORM = 'extraDeleteForm';
diff --git a/extension/qfq/qfq/QuickFormQuery.php b/extension/qfq/qfq/QuickFormQuery.php
index e9f28171b..c21158561 100644
--- a/extension/qfq/qfq/QuickFormQuery.php
+++ b/extension/qfq/qfq/QuickFormQuery.php
@@ -378,6 +378,8 @@ class QuickFormQuery {
         $form = $this->db->sql("SELECT * FROM Form AS f WHERE f." . F_NAME . " LIKE ? AND f.deleted='no'", ROW_EXPECT_1,
             [$formName], 'Form not found or multiple forms with the same name.');
 
+        $form = $this->modeAdjustFormConfig($mode, $form);
+
         $this->formSpec = $this->eval->parseArray($form);
         HelperFormElement::explodeParameter($this->formSpec);
 
@@ -495,6 +497,27 @@ class QuickFormQuery {
         return $formName;
     }
 
+    /**
+     * Depending on $mode various formSpec fields might be adjusted.
+     * E.g.: the form title is not important during a delete.
+     *
+     * @param $mode
+     * @param array $form
+     * @return array
+     */
+    private function modeAdjustFormConfig($mode, array $form) {
+
+        switch ($mode) {
+            case FORM_DELETE:
+                $form[F_TITLE] = '';
+                break;
+            default:
+                break;
+        }
+
+        return $form;
+    }
+
     /**
      * Check if loading of the given form is permitted. If not, throw an exception.
      *
-- 
GitLab