[TASK] Rework Condition apply/applies/negate methods. use reusable methods
[TYPO3CMS/Extensions/powermailCond.git] / Classes / Domain / Validator / ConditionAwareValidator.php
index 9e4bf95..297b95c 100644 (file)
@@ -28,7 +28,10 @@ namespace In2code\PowermailCond\Domain\Validator;
  ***************************************************************/
 
 use In2code\Powermail\Domain\Model\Field;
+use In2code\Powermail\Domain\Model\Form;
+use In2code\Powermail\Domain\Model\Page;
 use In2code\Powermail\Domain\Validator\InputValidator;
+use In2code\Powermail\Utility\ConfigurationUtility;
 use In2code\PowermailCond\Domain\Model\Condition;
 use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
 
@@ -50,15 +53,40 @@ class ConditionAwareValidator extends InputValidator {
                $feUser = $GLOBALS['TSFE']->fe_user;
                $arguments = $feUser->getSessionData('tx_powermail_cond');
                $fieldMarker = $field->getMarker();
-               if (!empty($arguments['todo'][$fieldMarker])) {
-                       if (!$arguments['todo'][$fieldMarker] === Condition::getActionNumberMap(Condition::ACTION_HIDE)) {
-                               // Mandatory Check
-                               if ($field->getMandatory()) {
-                                       if (!$this->validateMandatory($value)) {
-                                               $this->setErrorAndMessage($field, 'mandatory');
+
+
+               if (ConfigurationUtility::isReplaceIrreWithElementBrowserActive()) {
+                       $pages = $field->getPages();
+                       /** @var Form $form */
+                       foreach ($pages->getForms() as $form) {
+                               /** @var Page $page */
+                               foreach ($form->getPages() as $page) {
+                                       /** @var Field $field */
+                                       foreach ($page->getFields() as $field) {
+                                               if (!empty($arguments[$form->getUid()][$page->getUid()][$fieldMarker][Condition::INDEX_ACTION])) {
+                                                       if ($arguments[$form->getUid()][$page->getUid()][$fieldMarker][Condition::INDEX_ACTION] === Condition::ACTION_HIDE_STRING) {
+                                                               return;
+                                                       }
+                                               }
                                        }
                                }
                        }
+               } else {
+                       $page = $field->getPages();
+                       $form = $page->getForms()->getUid();
+                       $page = $page->getUid();
+                       if (!empty($arguments[Condition::INDEX_TODO][$form][$page][$fieldMarker][Condition::INDEX_ACTION])) {
+                               if ($arguments[Condition::INDEX_TODO][$form][$page][$fieldMarker][Condition::INDEX_ACTION] === Condition::ACTION_HIDE_STRING) {
+                                       return;
+                               }
+                       }
+               }
+
+               // Mandatory Check
+               if ($field->getMandatory()) {
+                       if (!$this->validateMandatory($value)) {
+                               $this->setErrorAndMessage($field, 'mandatory');
+                       }
                }
 
                // String Checks