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

Form\Factory can handle config with null elements #4971

Conversation

bacinsky
Copy link
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.

@grizzm0
Copy link
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;
    }

@bacinsky
Copy link
Contributor Author

@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.

@ezimuel
Copy link
Contributor

ezimuel commented Aug 19, 2013

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

@bacinsky
Copy link
Contributor Author

@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.

@ghost ghost assigned weierophinney Aug 19, 2013
weierophinney added a commit that referenced this pull request Aug 19, 2013
…ent-specification

Form\Factory can handle config with null elements
weierophinney added a commit that referenced this pull request Aug 19, 2013
@weierophinney weierophinney merged commit e32b4c7 into zendframework:develop Aug 19, 2013
@bacinsky bacinsky deleted the feature/form-factory-null-element-specification branch August 19, 2013 22:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants