示例#1
0
 /**
  * @param \TYPO3\Form\Core\Model\Page $page
  * @return \TYPO3\Flow\Error\Result
  * @internal
  */
 protected function mapAndValidatePage(\TYPO3\Form\Core\Model\Page $page)
 {
     $result = new \TYPO3\Flow\Error\Result();
     $requestArguments = $this->request->getArguments();
     $propertyPathsForWhichPropertyMappingShouldHappen = array();
     $registerPropertyPaths = function ($propertyPath) use(&$propertyPathsForWhichPropertyMappingShouldHappen) {
         $propertyPathParts = explode('.', $propertyPath);
         $accumulatedPropertyPathParts = array();
         foreach ($propertyPathParts as $propertyPathPart) {
             $accumulatedPropertyPathParts[] = $propertyPathPart;
             $temporaryPropertyPath = implode('.', $accumulatedPropertyPathParts);
             $propertyPathsForWhichPropertyMappingShouldHappen[$temporaryPropertyPath] = $temporaryPropertyPath;
         }
     };
     foreach ($page->getElementsRecursively() as $element) {
         $value = \TYPO3\Flow\Utility\Arrays::getValueByPath($requestArguments, $element->getIdentifier());
         $element->onSubmit($this, $value);
         $this->formState->setFormValue($element->getIdentifier(), $value);
         $registerPropertyPaths($element->getIdentifier());
     }
     // The more parts the path has, the more early it is processed
     usort($propertyPathsForWhichPropertyMappingShouldHappen, function ($a, $b) {
         return substr_count($b, '.') - substr_count($a, '.');
     });
     $processingRules = $this->formDefinition->getProcessingRules();
     foreach ($propertyPathsForWhichPropertyMappingShouldHappen as $propertyPath) {
         if (isset($processingRules[$propertyPath])) {
             $processingRule = $processingRules[$propertyPath];
             $value = $this->formState->getFormValue($propertyPath);
             try {
                 $value = $processingRule->process($value);
             } catch (\TYPO3\Flow\Property\Exception $exception) {
                 throw new \TYPO3\Form\Exception\PropertyMappingException('Failed to process FormValue at "' . $propertyPath . '" from "' . gettype($value) . '" to "' . $processingRule->getDataType() . '"', 1355218921, $exception);
             }
             $result->forProperty($propertyPath)->merge($processingRule->getProcessingMessages());
             $this->formState->setFormValue($propertyPath, $value);
         }
     }
     return $result;
 }
示例#2
0
 /**
  * @test
  */
 public function getProcessingRuleCreatesProcessingRuleIfItDoesNotExistYet()
 {
     $formDefinition = new FormDefinition('foo1');
     $processingRule1 = $formDefinition->getProcessingRule('foo');
     $processingRule2 = $formDefinition->getProcessingRule('foo');
     $this->assertInstanceOf('TYPO3\\Form\\Core\\Model\\ProcessingRule', $processingRule1);
     $this->assertSame($processingRule1, $processingRule2);
     $this->assertSame(array('foo' => $processingRule1), $formDefinition->getProcessingRules());
 }