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

InputFilter not populating/using FallbackValue for Input #10

Merged
merged 1 commit into from
Aug 3, 2015

Conversation

weierophinney
Copy link
Member

After updating from Version 2.3.5 to the newest Version i'm running into following error.

I'm creating an new InputFilter creating the Inputs in __construct() like this:

class ListDataInputFilter extends InputFilter {
    public function __construct() {
        $page = new \Zend\InputFilter\Input('page');
        $page->setFallbackValue(1);
        $this->add($page);
    }
}

Then i'm calling

// empty to demonstrate behaviour
$filterParams = array();
$filter = new ListDataFilter();
$filter->setData($filterParams);
if(!$filter->isValid()) {
    var_dump($filter->getMessages());
}

With Version 2.3.5 it's worked as expected. Populating the Fallback Value and not throwing an Error. But with 2.5.* instead of filling the Page Input with the Fallback Value it's empty and the Filter is not valid.

@weierophinney weierophinney added this to the 2.5.3 milestone Jul 30, 2015
@weierophinney weierophinney self-assigned this Jul 30, 2015
The patch modifies the logic of BaseInputFilter to ensure that if an
input supports fallback values (is an instanceof Input), and has
fallback value, then that fallback value will be considered when
determining validity of the input. In other words, if the value is
missing from the data set, the fallback value is assumed.

It also adds a test to ensure that if the value *is* passed but empty, the
fallback value is used for that input.
@weierophinney
Copy link
Member

@disasterdrop I've verified the issue, and:

  • created unit tests to cover the fallback value behavior, as we did not have any in the input filter tests (only the input tests);
  • created a patch to address the issue.

Please check the tests to make sure they're testing the behavior you need, and we'll get a release out with the fixes.

@weierophinney
Copy link
Member

When approved, we'll also release a 2.4 LTS version with the fix.

@akrabat
Copy link
Contributor

akrabat commented Jul 30, 2015

I've reviewed and it looks good to me. Feel free to merge.

@weierophinney
Copy link
Member

@disasterdrop Why did you close this? We haven't merged the patch yet!

@weierophinney weierophinney reopened this Aug 3, 2015
@disasterdrop
Copy link
Author

@weierophinney
Sorry for that...
I'm relative new to git and thought i would approve that your code was the right behaviour, after i testet your fix, liked you asked me to do.

@weierophinney weierophinney merged commit a7bed00 into zendframework:master Aug 3, 2015
weierophinney added a commit that referenced this pull request Aug 3, 2015
weierophinney added a commit that referenced this pull request Aug 3, 2015
weierophinney added a commit that referenced this pull request Aug 3, 2015
&& $hasFallback
) {
$input->setValue($input->getFallbackValue());
continue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the input to be append to validInputs collection?

weierophinney added a commit to weierophinney/zend-inputfilter that referenced this pull request Sep 8, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants