ElevatoDigital / dewdrop

Dewdrop makes writing complex WordPress plugins simpler by providing a sensible project layout and developer tools.
Other
11 stars 3 forks source link

Input filter being generated is only returning first field #67

Closed cornelisonc closed 8 years ago

cornelisonc commented 8 years ago
    /**
     * Get Fields for an item node
     * @return Fields node fields
     */
    public function getItemNodeFields()
    {
        $fields = new Fields();

        $fields
            ->add($this->field('name'))
            ->add($this->field('item_code_id'))
            ->add($this->field('item_enabled'))
        ;
            //->add($this->field('price'));
            //something is wrong with the filter on price (oddly it only happens when there are multiple fields)

        return $fields;
    }

In this use case, it's (weirdly) returning all fields for the first time it is getting called, but every subsequent time it is only returning $this->field('name'). The other fields are getting errored out silently. It looks like someone has already encountered this issue (see commented note on price) but it was mistakenly diagnosed as an issue with the price filter rather than any addt'l fields after 'name'. Not sure if there is something special about 'name' or if it just takes whatever the first field is.

darbyfelton commented 8 years ago

The behavior we were seeing is that the first time the following code is run, we get an input filter returned that composes input filters for each of the three fields in Ceili's comment above:

$packageProductFilter = Utility::generateInputFilter($productsModel->getPackageProductFields(), $package['package_product']);

The second time that the above code is run, we get an input filter that composes only a single input filter for the name field, but input filters for the item_code_id and item_enabled fields are not included, resulting in the unexpected behavior of the associated data being removed from the input.

griffbrad commented 8 years ago

The generateInputFilter() method you guys are referencing is not part of Dewdrop, but actually part of Group 10:

https://bitbucket.org/deltasystemsgroup/group10-ordermanagementsystem/src/9ea52b5485a7e56ecb1fabd52e8e736aa3b0c0f1/library/GroupTen/Utility.php?at=develop&fileviewer=file-view-default

The only Dewdrop code referenced in that method is Db\Field::

getInputFilter(), which could certainly have a bug. That seems unlikely to me because that method is pretty straightforward but also because I can't see how a problem in Db\Field::getInputFilter() would alter the number of inputs added in that loop.

I attempted to reproduce the issue in the context of Group 10 itself with the attached page file but was not able to trigger the bug. My page just calls generateInputFilter() multiple times with the same set of fields. After each call, I output the number of fields and the number of inputs in the filter. In both cases, I get 8 for of those counts.

Could you help me get this InputFilter.php file updated so that it reproduces the issue you're seeing? What am I missing? InputFilter.txt