[TASK] Add comments to ConditionContainer::applayConditions
authorOliver Eglseder <oliver.eglseder@in2code.de>
Tue, 8 Sep 2015 11:37:27 +0000 (13:37 +0200)
committerOliver Eglseder <oliver.eglseder@in2code.de>
Tue, 8 Sep 2015 11:37:27 +0000 (13:37 +0200)
Classes/Domain/Model/ConditionContainer.php

index 2b5d573..273f11b 100644 (file)
@@ -91,21 +91,39 @@ class ConditionContainer {
         * @return Form
         */
        public function applyConditions(Form $form, array $arguments) {
+
+               // run this loop if any condition changed something
+               // but stop after 100 rounds to prevent infinite loops (built by editors)
                while ($this->somethingChanged && $this->loopCount < 100) {
+
                        $this->somethingChanged = FALSE;
                        $this->loopCount++;
+
+                       // go through each condition
                        foreach ($this->conditions as $condition) {
+
+                               // if the rules match on the form
                                if ($condition->applies($form)) {
+
+                                       // then apply the changes the condition would make
                                        $newArguments = $condition->apply($form, $arguments);
                                } else {
+
+                                       // else "revert" the changes (un-hides previously hidden fields and vice versa)
                                        $newArguments = $condition->negate($form, $arguments);
                                }
+
+                               // If there were changes in the arguments (e.g. a field is now hidden)
                                if ($newArguments !== $arguments) {
                                        $this->somethingChanged = TRUE;
                                }
+
+                               // set the arguments for the next iteration
                                $arguments = $newArguments;
                        }
                }
+
+               // return the arguments with instructions for the JS in the frontend
                return $arguments;
        }