Skip to content

Commit

Permalink
Fix build, since new zend-inputfilter the NotEmpty validator was not …
Browse files Browse the repository at this point in the history
…added as expected. Now we add it ourself
  • Loading branch information
bramstroker committed Oct 8, 2015
1 parent 5308a8d commit d4f01cb
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/StrokerForm/Renderer/AbstractValidateRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
use Zend\Form\Element\Radio;
use Zend\Form\FieldsetInterface;
use Zend\InputFilter\InputFilterInterface;
use Zend\InputFilter\InputInterface;
use Zend\Validator\Csrf;
use Zend\Validator\NotEmpty;
use Zend\Validator\ValidatorChain;
use Zend\View\Renderer\PhpRenderer as View;
use Zend\Form\FormInterface;
use Zend\Validator\ValidatorInterface;
Expand Down Expand Up @@ -107,11 +110,34 @@ public function getValidatorsForElement(InputFilterInterface $inputFilter, Eleme
}
$input = $inputFilter->get($elementName);

// Make sure NotEmpty validator is added when input is required
$input->isValid();
$this->injectNotEmptyValidator($input);

return $input->getValidatorChain()->getValidators();
}

/**
* When the input is required we need to inject the NotEmpty validator
*
* @param InputInterface $input
*/
protected function injectNotEmptyValidator(InputInterface $input)
{
if (!$input->isRequired()) {
return;
}

$chain = $input->getValidatorChain();
return $chain->getValidators();

// Check if NotEmpty validator is already in chain
$validators = $chain->getValidators();
foreach ($validators as $validator) {
if ($validator['instance'] instanceof NotEmpty) {
return;
}
}

// Make sure NotEmpty validator is added when input is required
$chain->prependValidator(new NotEmpty());
}

/**
Expand Down

0 comments on commit d4f01cb

Please sign in to comment.