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

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

Open
coder-pm opened this issue Apr 28, 2017 · 1 comment

Comments

@coder-pm
Copy link

coder-pm commented Apr 28, 2017

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 Input filter specification not merged for Collection #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 Input filter specification not merged for Collection #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
Copy link
Member

This repository has been closed and moved to laminas/laminas-form; a new issue has been opened at laminas/laminas-form#15.

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

2 participants