Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Filters and validators are added twice when using fieldsets #5166

Closed
Nowicki opened this issue Sep 24, 2013 · 3 comments
Closed

Filters and validators are added twice when using fieldsets #5166

Nowicki opened this issue Sep 24, 2013 · 3 comments

Comments

@Nowicki
Copy link

Nowicki commented Sep 24, 2013

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
@Nowicki
Copy link
Author

Nowicki commented Sep 30, 2013

The same filter is added twice at line 816 and 772 after calling Zend\Form\Form::attachInputFilterDefaults() at line 819

@stefanotorresi
Copy link
Contributor

I did a reverse git bisect and found out that this has been fixed in 5d25d75, which is ahead of release-2.2.4.

here is a little test:

public function testInputFilterNotAddedTwiceWhenUsingFieldsets()
{
    $form = new \Zend\Form\Form();

    $fieldset = new \ZendTest\Form\TestAsset\FieldsetWithInputFilter('fieldset');
    $form->add($fieldset);
    $filters = $form->getInputFilter()->get('fieldset')->get('foo')->getFilterChain();
    $this->assertEquals(1, $filters->count());
}

someone let me know if we should add it to ZendTest\Form\FormTest for regression testing purposes.

affected users could try and use master branch until next maintenance release.

@Maks3w
Copy link
Member

Maks3w commented Oct 21, 2013

Duplicate #5050

@Maks3w Maks3w closed this as completed Oct 21, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants