[TASK] Backup Field values and consider hidden fields as empty. Filter encoded return...
authorOliver Eglseder <oliver.eglseder@in2code.de>
Thu, 10 Sep 2015 12:16:11 +0000 (14:16 +0200)
committerOliver Eglseder <oliver.eglseder@in2code.de>
Thu, 10 Sep 2015 12:16:11 +0000 (14:16 +0200)
Classes/Controller/ConditionController.php
Classes/Domain/Model/Condition.php

index 3e7bb3b..1f72f1f 100644 (file)
@@ -90,6 +90,9 @@ class ConditionController extends ActionController {
                $feUser->initFEuser();
                $feUser->fe_user->setAndSaveSessionData('tx_powermail_cond', $arguments);
 
+               unset($arguments['backup']);
+               unset($arguments['field']);
+
                return json_encode($arguments);
        }
 }
index 374db6b..6fdccd3 100644 (file)
@@ -49,6 +49,7 @@ class Condition extends AbstractEntity {
        const ACTION_UN_HIDE_STRING = 'un_hide';
        const INDEX_TODO = 'todo';
        const INDEX_ACTION = 'action';
+       const INDEX_BACKUP = 'backup';
        const INDEX_MATCHING_CONDITION = 'matching_condition';
 
        /**
@@ -345,7 +346,21 @@ class Condition extends AbstractEntity {
                        }
                }
                $arguments[self::INDEX_TODO][$formUid][$pageUid][$fieldMarker][self::INDEX_ACTION] = $action;
-               $arguments[self::INDEX_TODO][$formUid][$pageUid][$fieldMarker][self::INDEX_MATCHING_CONDITION][$conditionUid] = $conditionUid;
+               $arguments[self::INDEX_TODO][$formUid][$pageUid][$fieldMarker][self::INDEX_MATCHING_CONDITION][$conditionUid] =
+                       $conditionUid;
+
+               // Backup field value if field gets hidden
+               if ($action === self::ACTION_HIDE_STRING) {
+                       $arguments[self::INDEX_BACKUP][$formUid][$pageUid][$fieldMarker] = $field->getText();
+                       $field->setText('');
+               } else {
+                       // fill field with backup'd value if field gets enabled again
+                       if ($action === self::ACTION_UN_HIDE_STRING) {
+                               if (isset($arguments[self::INDEX_BACKUP][$formUid][$pageUid][$fieldMarker])) {
+                                       $field->setText($arguments[self::INDEX_BACKUP][$formUid][$pageUid][$fieldMarker]);
+                               }
+                       }
+               }
                return $arguments;
        }
 
@@ -359,7 +374,8 @@ class Condition extends AbstractEntity {
        protected function applyOnPage($formUid, Page $page, array $arguments, $action) {
                $pageUid = $page->getUid();
                foreach ($page->getFields() as $field) {
-                       $arguments = $this->applyOnField($formUid, $pageUid, $field, $arguments, $action, ($action === self::ACTION_UN_HIDE_STRING));
+                       $arguments =
+                               $this->applyOnField($formUid, $pageUid, $field, $arguments, $action, ($action === self::ACTION_UN_HIDE_STRING));
                }
                $conditionUid = $this->getUid();
                $arguments[self::INDEX_TODO][$formUid][$pageUid][self::INDEX_ACTION] = $action;