Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[TwigBridge] Form option is settable only for first created form #45229

Copy link
Copy link
Closed
@maxkain

Description

@maxkain
Issue body actions

Symfony version(s) affected

5.4.2

Description

The problem appears when running symfony as a daemon with swoole web server. The option block_prefix is settable once. In other requests it is impossible to set this option to another value. Twig renders form as the block_prefix is not changed, although each time new form instance is created.

How to reproduce

Example is from EasyCorp\Bundle\EasyAdminBundle\Factory:

$this->symfonyFormFactory->createNamedBuilder($entityDto->getName(), CrudFormType::class, $entityDto->getInstance(), $formOptions->all());

If set first parameter to something random value the problem disappears.

And in controller set option like this:

if ($someCondition) {
    $field->getAsDto()->setFormTypeOption('block_prefix',  'some_prefix');
}

Possible Solution

I have decorated twig.form.engine (Symfony\Bridge\Twig\Form\TwigRendererEngine) with function, which is called on kernel.request event:

    public function init()
    {
        $this->resources = [];
    }

It works, but I am not sure it is the right solution.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.