Esempio n. 1
0
 /**
  * @param \Neos\Form\Core\Model\Page $page
  * @return \Neos\Error\Messages\Result
  * @internal
  */
 protected function mapAndValidatePage(\Neos\Form\Core\Model\Page $page)
 {
     $result = new \Neos\Error\Messages\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 = \Neos\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 (\Neos\Flow\Property\Exception $exception) {
                 throw new \Neos\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(\Neos\Form\Core\Model\AbstractFormElement::class)->setMethods(array('dummy'))->disableOriginalConstructor()->getMock();
     $element2 = $this->getMockBuilder(\Neos\Form\FormElements\Section::class)->setMethods(array('dummy'))->disableOriginalConstructor()->getMock();
     $element21 = $this->getMockBuilder(\Neos\Form\Core\Model\AbstractFormElement::class)->setMethods(array('dummy'))->disableOriginalConstructor()->getMock();
     $element22 = $this->getMockBuilder(\Neos\Form\Core\Model\AbstractFormElement::class)->setMethods(array('dummy'))->disableOriginalConstructor()->getMock();
     $element2->addElement($element21);
     $element2->addElement($element22);
     $element3 = $this->getMockBuilder(\Neos\Form\Core\Model\AbstractFormElement::class)->setMethods(array('dummy'))->disableOriginalConstructor()->getMock();
     $page->addElement($element1);
     $page->addElement($element2);
     $page->addElement($element3);
     $this->assertSame(array($element1, $element2, $element21, $element22, $element3), $page->getElementsRecursively());
 }