craue / CraueFormFlowBundle

Multi-step forms for your Symfony project.
MIT License
736 stars 118 forks source link

Call to a member function getCurrentRequest() on null #325

Open igorjacon opened 6 years ago

igorjacon commented 6 years ago

I know this is a duplicate of issue 318 but I'm having the same problem and that issue is closed but no explanation given.

I have the same setup, can someone help?

Thanks

igorjacon commented 6 years ago

@craue

Andrufus commented 6 years ago

Hi I solved this by configuring the service like this :

app.form.registration:
    class: AppBundle\Form\RegistrationFlow
    parent: craue.form.flow
    public: true
    autowire: true
    autoconfigure: false
Gerfaut commented 5 years ago

Hello @igorjacon, @Andrufus is this quick fix still working with last version of symfony? I'm still struggling with the exact same error you had.

Thanks for your help!

@craue will this bundle be updated to work with last version of symfony (and the new DI system)? Thanks,

Gerfaut

Andrufus commented 5 years ago

Hi @Gerfaut I used this config with Symfony 3.4.3. I didn't test on any other version.

igorjacon commented 5 years ago

Hi @Gerfaut

It's working for me on Symfony 4. I created a new service config like so:

services:
    App\Form\Vendor\RegistrationFlow\VendorRegistrationType:
        parent: craue.form.flow
        public: true
        autowire: true
        autoconfigure: false
Gerfaut commented 5 years ago

@igorjacon that's weird, I tried this too on Symfony 4.1.5 and it was not working properly. I'll retry this evening :)

igorjacon commented 5 years ago

On what service file did you add that service config? I had to create a different service file. Hope that helps.

Gerfaut commented 5 years ago

Hello @igorjacon, OK, I got it and you were right in your previous answer!

I was declaring my service like this:

       app.form.RegistrationFlow:
           class: App\Form\Vendor\RegistrationFlow\VendorRegistrationType
           parent: craue.form.flow
           public: true
           autowire: true
           autoconfigure: false

So with an alias... And this was not working.

But if I take your example:

services:
    App\Form\Vendor\RegistrationFlow\VendorRegistrationType:
        parent: craue.form.flow
        public: true
        autowire: true
        autoconfigure: false

So without alias and declaring it directly with the class it works perfectly and I can then inject it in my Controller constructor or method.

/**
* @Route("/create")
*/
public function create(VendorRegistrationType $vendorRegistrationType)
{
     .... 
}

And to answer to your last question, I was able to add this directly in the existing services.yaml.

Thanks a lot for your help and very quick answer !! 👍

Gerfaut

igorjacon commented 5 years ago

Awesome, I'm glad it works 👍

gnutix commented 5 years ago

I faced the following issue when trying to use the parent: craue.form.flow to define my flow service :

The service "\Our\Flow" cannot use the "parent" option in the same file where "_instanceof" configuration is defined as using both is not supported. Move your child definitions to a separate file.

We tried moving the service definition to another file, but it didn't work out at first (probably because we forgot clearing the cache at the time). So we used this solution instead :

services:
    // our defaults config
    _defaults:
        autowire: true
        autoconfigure: true
        public: false

    _instanceof:
        // others custom definitions here

        Craue\FormFlowBundle\Form\FormFlow:
            calls:
                - [setDataManager, ['@craue.form.flow.data_manager']]
                - [setFormFactory, ['@form.factory']]
                - [setRequestStack, ['@request_stack']]
                - [setEventDispatcher, ['@?event_dispatcher']]

It would be nice if this was correctly set by the bundle using Symfony's autoconfigure/_instanceof features.

craue commented 5 years ago

See #333.