Form\Factory can handle config with null elements #4971

Merged
merged 1 commit into from Aug 19, 2013

Projects

None yet

4 participants

@bacinsky
Contributor

There is an use case, when I have configured form with elements, but I want to disable some elements later in the config of the other module. So I override it with null, but the Form\Factory doesn't recognize it, so it needs a little fix.

Contributor
grizzm0 commented Aug 16, 2013

Why don't you simply use $form->remove('baz'); instead of setting the element to null?

    /**
     * Remove a named element or fieldset
     *
     * @param  string $elementOrFieldset
     * @return FieldsetInterface
     */
    public function remove($elementOrFieldset)
    {
        if (!$this->has($elementOrFieldset)) {
            return $this;
        }

        $entry = $this->byName[$elementOrFieldset];
        unset($this->byName[$elementOrFieldset]);

        $this->iterator->remove($entry);

        if ($entry instanceof FieldsetInterface) {
            unset($this->fieldsets[$elementOrFieldset]);
            return $this;
        }

        unset($this->elements[$elementOrFieldset]);
        return $this;
    }
Contributor

@grizzm0 Hi, you don't understand. I don't even want to add it. It's about merging configs and creating the form without accessing its instance.

I want to disable some elements later in the config of the other module.

That means statically, not runtime.

Owner
ezimuel commented Aug 19, 2013

@bacinsky can you provide an example for that scenario? Why you want to set a form element to null?

Contributor

@ezimuel I already wrote it. Imagine you have a module with configuration for the form. That form has some elements (maybe only one) I don't want to use in some applications, so I override the config with the null for that element, because it can't be removed by merge. I think this is easy to understand, maybe my bad English cause misunderstanding.

@weierophinney weierophinney added a commit that referenced this pull request Aug 19, 2013
@weierophinney weierophinney Merge branch 'feature/4971' into develop
Close #4971
ec49907
@weierophinney weierophinney merged commit e32b4c7 into zendframework:develop Aug 19, 2013

1 check passed

default The Travis CI build passed
Details
@bacinsky bacinsky deleted the bacinsky:feature/form-factory-null-element-specification branch Aug 19, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment