zendframework / zend-form

Form component from Zend Framework
BSD 3-Clause "New" or "Revised" License
69 stars 87 forks source link

Inconsistent input filter while using "preferFormInputFilter" form option #160

Open coder-pm opened 7 years ago

coder-pm commented 7 years ago

InputFilter merging is inconsistent after #78 (was buggy before). I'll explain it basing on example below:

$factory = new \Zend\Form\Factory;
$form = $factory->createForm([
    'fieldsets' => [
        [
            'spec' => [
                'name' => 'baseFieldset',
                'type' => 'Zend\Form\InputFilterProviderFieldset',
                'elements' => [
                    [
                        'spec' => [
                            'name' => 'select',
                            'type' => 'select',
                            'options' => [
                                'value_options' => [
                                    1 => 'foo',
                                    2 => 'bar'
                                ]
                            ]
                        ],
                    ],
                    [
                        'spec' => [
                            'name' => 'collection',
                            'type' => 'collection',
                            'options' => [
                                'target_element' => [
                                    'type' => 'Zend\Form\InputFilterProviderFieldset',
                                    'elements' => [
                                        [
                                            'spec' => [
                                                'name' => 'select',
                                                'type' => 'select',
                                                'options' => [
                                                    'value_options' => [
                                                        1 => 'foo',
                                                        2 => 'bar'
                                                    ]
                                                ]
                                            ]
                                        ]
                                    ],
                                    'options' => [
                                        'input_filter_spec' => [
                                            'select' => [
                                                'required' => false
                                            ]
                                        ]
                                    ]
                                ]
                            ]
                        ]
                    ]
                ],
                'options' => [
                    'use_as_base_fieldset' => true,
                    'input_filter_spec' => [
                        'select' => [
                            'required' => false
                        ]
                    ]
                ]
            ]
        ]
    ],
    'options' => [
        'prefer_form_input_filter' => false
    ]
]);
$inputFilter = $form->getInputFilter();
$fieldsetElementInputFilter = $inputFilter->get('baseFieldset')->get('select');
$collectionElementInputFilter = $inputFilter->get('baseFieldset')->get('collection')->getInputFilter()->get('select');
$this->assertCount(1, $fieldsetElementInputFilter->getValidatorChain()->getValidators());
$this->assertCount(1, $collectionElementInputFilter->getValidatorChain()->getValidators());
  1. How it worked before #78 Case 1 prefer_form_input_filter => true sizeof($fieldsetElementInputFilter->getValidatorChain()->getValidators()) === 0 sizeof($collectionElementInputFilter->getValidatorChain()->getValidators()) === 0 Case 2 prefer_form_input_filter => false sizeof($fieldsetElementInputFilter->getValidatorChain()->getValidators()) === 1 sizeof($collectionElementInputFilter->getValidatorChain()->getValidators()) === 0

  2. How it works after #78 (now) Case 1 prefer_form_input_filter => true sizeof($fieldsetElementInputFilter->getValidatorChain()->getValidators()) === 0 sizeof($collectionElementInputFilter->getValidatorChain()->getValidators()) === 1 Case 2 prefer_form_input_filter => false sizeof($fieldsetElementInputFilter->getValidatorChain()->getValidators()) === 1 sizeof($collectionElementInputFilter->getValidatorChain()->getValidators()) === 1

  3. How it should work (my guess, but other behavior will mislead developers) Case 1 prefer_form_input_filter => true sizeof($fieldsetElementInputFilter->getValidatorChain()->getValidators()) === 0 sizeof($collectionElementInputFilter->getValidatorChain()->getValidators()) === 0 Case 2 prefer_form_input_filter => false sizeof($fieldsetElementInputFilter->getValidatorChain()->getValidators()) === 1 sizeof($collectionElementInputFilter->getValidatorChain()->getValidators()) === 1

As far as I remember, prefer_form_input_filter was introduced to prevent BC break, but right now we did the same for collections input filter (and this is also BC break).

weierophinney commented 4 years ago

This repository has been closed and moved to laminas/laminas-form; a new issue has been opened at https://github.com/laminas/laminas-form/issues/15.