Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering of the form panel of the profiler breaks due to data.id being undefined #29291

Closed
stof opened this issue Nov 23, 2018 · 7 comments
Closed

Comments

@stof
Copy link
Member

stof commented Nov 23, 2018

Symfony version(s) affected: 3.4.18

Description
The macro form_tree_details and form_tree_entry uses data.id in a lot of places. Some of them check for it to be defined, but some others don't. And I got a case where it fails:

Twig_Error_Runtime:
Neither the property "id" nor one of the methods "id()", "getid()"/"isid()"/"hasid()" or "__call()" exist and have public access in class "Symfony\Component\VarDumper\Cloner\Data".

  at vendor/symfony/symfony/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/form.html.twig:429

How to reproduce
I don't have a standalone reproducer for now.

@stof
Copy link
Member Author

stof commented Nov 23, 2018

note that it does not happen each time. I had one case with a displayed form which worked, while another profile with a submitted form (same form) broke.

@ro0NL
Copy link
Contributor

ro0NL commented Nov 23, 2018

Tried to reproduce, without any luck so far.

Looking at code there should always be an id set 🤔

Do you have some hints about the form structure. Does it happen on the root- or a child-form?

@stof
Copy link
Member Author

stof commented Nov 23, 2018

I have a CollectionType in this form. The missing id happens for the first element in this collection.

I think this is related to the fact that the fields are added in a PRE_SUBMIT listener. Maybe extractConfiguration is not called properly for dynamic fields, and so the data is incomplete.

@ro0NL
Copy link
Contributor

ro0NL commented Nov 23, 2018

For

public function __invoke(FormFactoryInterface $f, Request $r)
{
    $form = $f->createBuilder();
    $form->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $e) {
        $e->getForm()->add('coll', CollectionType::class, ['data' => ['foo']]);
    });
    $form->add('submit', SubmitType::class);
    $form = $form->getForm();
    $form->handleRequest($r);

    return $this->render('index.html.twig', ['form' => $form->createView()]);
}

After submit i see id=form_coll_0 for a view variable in the profiler.

Nevertheless, this code looks related:

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/DataCollector/FormDataCollector.php#L307-L322

The first $output variable is ignored here.

@stof
Copy link
Member Author

stof commented Nov 24, 2018

I'm not adding the collection type itself in a PRE_SUBMIT. But the collection type itself adds new children here.

@WubbleWobble
Copy link

WubbleWobble commented Oct 8, 2019

We ran into this bug too. Not sure what's causing it, but this does reproduce the issue:
https://github.com/WubbleWobble/symfony-issue-29291

@yceruto
Copy link
Member

yceruto commented Oct 16, 2019

Fixed in #33999

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

No branches or pull requests

6 participants