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

render() public method

If no errors are there, it renders the -child.
public render ( string $for = null ) : string
$for string The argument or property name or path to check for error(s)
return string
    public function render($for = null)
    {
        /** @var $request ActionRequest */
        $request = $this->controllerContext->getRequest();
        /** @var $validationResults Result */
        $validationResults = $request->getInternalArgument('__submittedArgumentValidationResults');
        if ($validationResults !== null) {
            // if $for is not set, ->forProperty will return the initial Result object untouched
            $validationResults = $validationResults->forProperty($for);
            if ($validationResults->hasErrors()) {
                return $this->renderThenChild();
            }
        }
        return $this->renderElseChild();
    }

Usage Example

 /**
  * @test
  */
 public function queriesResultForPropertyIfPropertyPathIsGiven()
 {
     $resultMock = $this->createMock(\Neos\Error\Messages\Result::class);
     $resultMock->expects($this->once())->method('forProperty')->with('foo.bar.baz')->will($this->returnValue(new Result()));
     /** @var $requestMock \PHPUnit_Framework_MockObject_MockObject */
     $requestMock = $this->request;
     $requestMock->expects($this->once())->method('getInternalArgument')->with('__submittedArgumentValidationResults')->will($this->returnValue($resultMock));
     $this->viewHelper->render('foo.bar.baz');
 }
IfHasErrorsViewHelper