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

FormElementManager compatibility break at 2.7 #62

Closed
chris-moreton opened this issue Apr 25, 2016 · 4 comments
Closed

FormElementManager compatibility break at 2.7 #62

chris-moreton opened this issue Apr 25, 2016 · 4 comments
Assignees
Labels
Milestone

Comments

@chris-moreton
Copy link

The behaviour of FormElementManager::get has changed as of version 2.7.0.

I have a project that creates a form with code such as the following:

$fem = $this->getServiceLocator()->get('FormElementManager');
$form = $fem->get('Application\Form\Lpa\ApplicantForm', ['lpa'=>$this->getLpa()]);

Which creates a form with the constructor:

    public function __construct($name, $options)
    {
        if(array_key_exists('lpa', $options)) {
            $this->lpa = $options['lpa'];
            unset($options['lpa']);
        }

        parent::__construct($name, $options);
    }

When I upgrade to version 2.7.0 or higher of Zend Form, this causes my application to fail. It turns out that the $options argument is being passed in as the $name argument, and there is no second argument to the form constructor.

Prior to 2.7.0, $name would come in as "Application\Form\Lpa\ApplicantForm", as expected, and $options would come in as the array that was passed to FormElementManager::get.

I have been digging through the code trying to identify where this behaviour changed, so far without success. I will keep looking.

@chris-moreton
Copy link
Author

The problem here turns out to be the removal of the createFromInvokable function from FormElementManager which was being called from doCreate in ServiceManager. The removal of this function results in the createFromInvokable function from AbstractPluginManager being called, which creates the object with

$instance = new $invokable($this->creationOptions);

as opposed to

$instance = new $invokable($name, $options);

which was the code from the FormElementManager version of createFromInvokable.

@Slamdunk
Copy link
Contributor

I tried to extend your concerns in #63

@weierophinney
Copy link
Member

@netsensia How are you configuring your elements?

Internally, we've updated all shipped elements such that instead of mapping as invokables, they map to a new Zend\Form\ElementFactory, which performs the logic that was originally in createFromInvokable().

My guess is you're mapping your instances as invokables, and pointing them to Element::class. Can you confirm?

@weierophinney weierophinney added this to the 2.8.2 milestone Apr 28, 2016
@weierophinney weierophinney self-assigned this Apr 28, 2016
weierophinney added a commit that referenced this issue May 1, 2016
@chris-moreton
Copy link
Author

@weierophinney My apologies - I missed these updates. The hotfix has solved the problem - thank you.

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

No branches or pull requests

3 participants