문제

I wrote about it on zf2 github and no one answered yet. But maybe it's not a bug and I'm doing something wrong. Here is my code:

Fieldset

class TestFieldset extends Fieldset implements
    InputFilterProviderInterface
{
    public function __construct($name)
    {
        parent::__construct($name);

        $this->add(array(
            'type' => 'text',
            'name' => 'test'
        ));
    }

    public function getInputFilterSpecification() {
        return array(
            'test' => array(
                'filters' => array(
                    array('name' => 'StringTrim')
                ),
                'validators' => array(
                    array('name' => 'NotEmpty')
                )
            )
        );
    } 
}

Form

class TestForm extends Form
{
    public function __construct($name = null, $options = array()) {
        parent::__construct($name, $options);

        $fieldset = new TestFieldset('test-fieldset');

        $this->add($fieldset);
    }
}

Controller action

public function indexAction()
{
    $form = new \CRM\Form\TestForm;    
    $form->setData(array('test-fieldset' => array('test' => 'test value')));
    $form->isValid();

    $inputFilter = $form->getInputFilter()
            ->get('test-fieldset')
            ->get('test');

    $filters = $inputFilter->getFilterChain()
        ->getFilters();

    $validators = $inputFilter->getValidatorChain()
        ->getValidators();

    var_dump($filters);
    var_dump($validators);
}

Result

object(Zend\Stdlib\PriorityQueue)[678]
  protected 'queueClass' => string 'Zend\Stdlib\SplPriorityQueue' (length=28)
  protected 'items' => 
    array (size=2)
      0 => 
        array (size=2)
          'data' => 
            object(Zend\Filter\StringTrim)[682]
              ...
          'priority' => int 1000
      1 => 
        array (size=2)
          'data' => 
            object(Zend\Filter\StringTrim)[693]
              ...
          'priority' => int 1000
  protected 'queue' => 
    object(Zend\Stdlib\SplPriorityQueue)[683]
      protected 'serial' => int 2147483645
array (size=2)
  0 => 
    array (size=2)
      'instance' => 
        object(Zend\Validator\NotEmpty)[686]
          protected 'constants' => 
            array (size=13)
              ...
          protected 'messageTemplates' => 
            array (size=2)
              ...
          protected 'options' => 
            array (size=1)
              ...
          protected 'value' => string 'test value' (length=10)
          protected 'abstractOptions' => 
            array (size=7)
              ...
      'breakChainOnFailure' => boolean false
  1 => 
    array (size=2)
      'instance' => 
        object(Zend\Validator\NotEmpty)[697]
          protected 'constants' => 
            array (size=13)
              ...
          protected 'messageTemplates' => 
            array (size=2)
              ...
          protected 'options' => 
            array (size=1)
              ...
          protected 'value' => string 'test value' (length=10)
          protected 'abstractOptions' => 
            array (size=7)
              ...
      'breakChainOnFailure' => boolean false

As you can see, there are two StringTrim filters and two NotEmpty validators. It's annoying especially when I'm using File\RenameUpload filter and it's trying to rename and move already renamed file.

도움이 되었습니까?

해결책

This bug was fixed in zf 2.2.5 https://github.com/zendframework/zf2/issues/5270

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top