Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
weierophinney opened this issue Dec 31, 2019 · 0 comments

Comments

@weierophinney
Copy link
Member

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 FormText & FormTextarea: Allow attribute InputMode #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 FormText & FormTextarea: Allow attribute InputMode #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).


Originally posted by @coder-pm at zendframework/zend-form#160

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant