CraueFormFlowBundle icon indicating copy to clipboard operation
CraueFormFlowBundle copied to clipboard

How to configure bundle to use Doctrine Storage

Open nestordedios opened this issue 5 years ago • 3 comments

Hi,

Is there any documentation/example where it explains how to configure the bundle to use the Doctrine Storage instead of the default Session Storage?

I've been searching in the repository but I couldn't find something helpful.

Do you have any recommendation?

nestordedios avatar Dec 16 '20 20:12 nestordedios

There's only https://github.com/craue/CraueFormFlowBundle/pull/217#issuecomment-343450121 for now. A doc PR would be appreciated. 😏

craue avatar Dec 16 '20 21:12 craue

Thanks @craue !

I tried in services.yml with:

app.form.flow.user_session_storage_key:
        class: Craue\FormFlowBundle\Storage\UserSessionStorageKeyGenerator
        arguments: ['@security.token_storage', '@session']
    app.form.flow.storage.doctrine:
        class: Craue\FormFlowBundle\Storage\DoctrineStorage
        public: false
        arguments: ['@doctrine.dbal.default_connection', '@app.form.flow.user_session_storage_key']
    app.form.flow.data_manager:
        class: Craue\FormFlowBundle\Storage\DataManager
        public: false
        arguments: ['@app.form.flow.storage.doctrine']
    app.form.flow:
        class: 'App\Form\RegistrationFlow'
        calls:
        - [setDataManager, ['@app.form.flow.data_manager']]
        - [setFormFactory, ['@form.factory']]
        - [setRequestStack, ['@request_stack']]
        - [setEventDispatcher, ['@?event_dispatcher']]

but it seems the Storage being used is still SessionStorage instead of DoctrineStorage. When I dump dump($this->flow->getDataManager()->getStorage()); I get the following:

Capture

Is there something more that needs to be done after configuration? Are there any examples or docs on how to use the bundle with the Doctrine Storage?

Any help is much appreciated.

nestordedios avatar Dec 17 '20 09:12 nestordedios

@nestordedios, this config basically works for me, but make sure the flow is actually used.

-    app.form.flow:
-        class: 'App\Form\RegistrationFlow'
+    App\Form\RegistrationFlow:
// controller:
public function registrationAction(\App\Form\RegistrationFlow $flow) {
	assert($flow->getDataManager()->getStorage() instanceof \Craue\FormFlowBundle\Storage\DoctrineStorage);
	// ...
}

craue avatar Dec 23 '20 11:12 craue