-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Wrong template block used for a nested CollectionType element #37024
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
Comments
I have the same problem with form collections, and commenting the pointed line does stop it from happening for me too. |
+1 |
Same problem here |
If anyone is having this issue and can't wait for a fix, here's a temporary one with an intermediate class. Create this file somewhere: <?php
// src\Form\MyCollectionType.php
namespace App\Form;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
/**
* TODO: Remove this class when issue #37024 is fixed.
*
* @see https://github.com/symfony/symfony/issues/37024
*/
class MyCollectionType extends CollectionType
{
public function finishView(FormView $view, FormInterface $form, array $options)
{
trigger_deprecation('', '', "Don't forget to remove the class MyCollectionType");
if ($form->getConfig()->hasAttribute('prototype') && $view->vars['prototype']->vars['multipart']) {
$view->vars['multipart'] = true;
}
}
} Now you can use it instead of It basically overrides the |
I can confirm this issue, and I'm trying to find the original cause to solve it. I don't think #36088 is the root problem, but might be related to the fact there is no form theme defined for this new block prefix Temporarily, I solved it by adding this theme to my project: {%- block collection_entry_widget -%}
{{ form_widget(form) }}
{%- endblock -%} |
Yes, the block prefixes hierarchy was incorrect, the new It should be fixed in #37276 |
…e (yceruto) This PR was merged into the 5.1 branch. Discussion ---------- [Form] Fixed block prefixes hierarchy of the CollectionType | Q | A | ------------- | --- | Branch? | 5.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #37024 | License | MIT | Doc PR | - /cc @HeahDude Commits ------- a8f2c60 fixed block prefixes hierarchy of the CollectionType
…lectionType (yceruto) This PR was merged into the 5.1 branch. Discussion ---------- [Form] Fixed prototype block prefixes hierarchy of the CollectionType | Q | A | ------------- | --- | Branch? | 5.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #37024 | License | MIT | Doc PR | Following #37276 Commits ------- 65efc36 fixed prototype block prefixes hierarchy of the CollectionType
Hi @yceruto
Any Idea how this could be fixed? |
Hi @toooni, could you please create/share a small app reproducing your issue? thanks! |
Hi. I still have this problem after migration to Symfony 5.4 from 4.4. A simple of the structure:
I've changed an initial value in extended class of use Symfony\Component\Form\Extension\Core\Type\CollectionType as SymfonyCollectionType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
class CollectionType extends SymfonyCollectionType
{
public function finishView(FormView $view, FormInterface $form, array $options)
{
$prefixOffset = -5; // $prefixOffset = -2;
// next original code
}
} It solves the issue only when the value -5 or less (-6, -7, etc). |
@dmitrach Please open a new issue and provide a small example application that allows to reproduce your issue. |
Symfony version(s) affected: 5.1
Description
When a CollectionType is a child element of a form type, that itself is used in a CollectionType, and both form types define a _widget block to override default rendering, then the block of the outer type is used for both (inner and outer form) types.
This will most likely produce an exception, as the inner form does not define the properties needed by the block of the outer form.
How to reproduce
A minimal reproducer can be found here: https://github.com/jbtronics/symfony_bug
Assume we have multiple forms:
If you now define custom styles for the elements
then the code will break on Symfony 5.1, as
element1_widget
block is used for rendering both Element1Type and Element2Type elements, which will throw an exception (Neither the property "id" nor one of the methods "id()", "getid()"/"isid()"/"hasid()" or "__call()" exist and have public access in class "Symfony\Component\Form\FormView"
).Possible Solution
The bug was somehow introduced by pull #36088 (Added collectzion_entry block), and especially this line, as commenting this line, stops the wrong behavior.
The text was updated successfully, but these errors were encountered: