Neos\FluidAdaptor\ViewHelpers\Validation\ResultsViewHelper::render PHP Method

render() public method

Iterates through selected errors of the request.
public render ( string $for = '', string $as = 'validationResults' ) : string
$for string The name of the error name (e.g. argument name or property name). This can also be a property path (like blog.title), and will then only display the validation errors of that property.
$as string The name of the variable to store the current error
return string Rendered string
    public function render($for = '', $as = 'validationResults')
    {
        $request = $this->controllerContext->getRequest();
        /** @var $validationResults Result */
        $validationResults = $request->getInternalArgument('__submittedArgumentValidationResults');
        if ($validationResults !== null && $for !== '') {
            $validationResults = $validationResults->forProperty($for);
        }
        $this->templateVariableContainer->add($as, $validationResults);
        $output = $this->renderChildren();
        $this->templateVariableContainer->remove($as);
        return $output;
    }

Usage Example

 /**
  * @test
  */
 public function renderAddsValidationResultsForOnePropertyIfForArgumentIsNotEmpty()
 {
     $mockPropertyValidationResults = $this->getMockBuilder(\Neos\Error\Messages\Result::class)->getMock();
     $mockValidationResults = $this->getMockBuilder(\Neos\Error\Messages\Result::class)->getMock();
     $mockValidationResults->expects($this->once())->method('forProperty')->with('somePropertyName')->will($this->returnValue($mockPropertyValidationResults));
     $this->request->expects($this->atLeastOnce())->method('getInternalArgument')->with('__submittedArgumentValidationResults')->will($this->returnValue($mockValidationResults));
     $this->templateVariableContainer->expects($this->at(0))->method('add')->with('validationResults', $mockPropertyValidationResults);
     $this->viewHelper->expects($this->once())->method('renderChildren');
     $this->templateVariableContainer->expects($this->at(1))->method('remove')->with('validationResults');
     $this->viewHelper->render('somePropertyName');
 }
ResultsViewHelper