Esempio n. 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;
 }
Esempio n. 2
0
 /**
  * @test
  */
 public function getElementsRecursivelyReturnsRecursiveFormElementsInCorrectOrder()
 {
     $page = new Page('foo');
     $element1 = $this->getMockBuilder('TYPO3\\Form\\Core\\Model\\AbstractFormElement')->setMethods(array('dummy'))->disableOriginalConstructor()->getMock();
     $element2 = $this->getMockBuilder('TYPO3\\Form\\FormElements\\Section')->setMethods(array('dummy'))->disableOriginalConstructor()->getMock();
     $element21 = $this->getMockBuilder('TYPO3\\Form\\Core\\Model\\AbstractFormElement')->setMethods(array('dummy'))->disableOriginalConstructor()->getMock();
     $element22 = $this->getMockBuilder('TYPO3\\Form\\Core\\Model\\AbstractFormElement')->setMethods(array('dummy'))->disableOriginalConstructor()->getMock();
     $element2->addElement($element21);
     $element2->addElement($element22);
     $element3 = $this->getMockBuilder('TYPO3\\Form\\Core\\Model\\AbstractFormElement')->setMethods(array('dummy'))->disableOriginalConstructor()->getMock();
     $page->addElement($element1);
     $page->addElement($element2);
     $page->addElement($element3);
     $this->assertSame(array($element1, $element2, $element21, $element22, $element3), $page->getElementsRecursively());
 }