Issue with CollectionField and useEntryCrudForm in EasyAdminBundle
Describe the bug
-
Related Entity Fields Retrieval: In the current implementation, if the fields for the related entity (e.g., Comment) are not defined explicitly in the configureFields() function of the related CRUD controller (CommentCrudController), the fields are automatically inherited from the current CRUD controller (PostCrudController). This behavior leads to unexpected field inheritance and requires explicit definition of fields in the related CRUD controller, even if they are intended to be different.
-
Initial Values in CollectionField: When attempting to set specific initial values for fields in the related entity (e.g., setting the type field to "TEST" when creating a new comment), the specified initial values are not reflected in the CollectionField. While the initial values work correctly when creating the entity through its CRUD form, the same values are not propagated to the CollectionField. This inconsistency creates difficulties in maintaining uniform data across related entities within the collection.
To Reproduce
- Create two entities: Post and Comment, set up a OneToMany relationship between them.
- Use CollectionField in the PostCrudController to manage related comments.
- Attempt to set specific initial values for fields in Comment entity when creating a new comment.
Expected Behavior
- Related entity fields should be customizable in the CollectionField without the need for explicit definition in the related CRUD controller.
- Initial values set in the related entity should be reflected in the CollectionField when adding new related entities.
Actual Behavior
- Related entity fields are inherited from the current CRUD controller, leading to unexpected field inheritance in the CollectionField.
- Initial values set in the related entity are not propagated to the CollectionField.
(OPTIONAL) Additional context EasyAdmin-bundle: 4.8.3 Symfony: 6.3.7 PHP: 8.2.10
Thank you for your attention to this issue. Please let me know if you need any further information or clarification.
Code configuration of PostCrudController.php and CommentCrudController.php:
Below images of admin dashboard for Post and Comment. In Post->Comment Collections I expected added comment with type "TEST". Unfortunately i have null value :/
Below attached src code with example.
Maybe just copy paste the configurations in the ticket directly. :eyes:
I added the configuration of AdminCrud for Post and Comment. I'm sure this is a bug because if I comment the option to configure fields in a comment, the fields in the form that apply to the parent class appear. In my case the Post class. I can configure the fields and everything saves fine. Unfortunately, I cannot affect other properties of the Comment class. I'm trying to put dd() in the createEntity(), updateEntity() functions but it seems I can't refer to it if the collection field is created in the Post class.
Should be easy to fix, let me have a look real quick as I am just working with the CollectionField at the moment anyway.
I have made a simple adaption in the PR above, but I'd kindly ask you to modify your local code base respectively and give feedback to me so I know if thats fixing your issue.
Also, 6000th PR in this project. :D
Unfortunately, if I set a name in a new object, I still don't see it in the collection. If in the method createEntity of CommentCrudController I do
$entity = new $entityFqcn;
$entity->setName('TEST');
return $entity;
Nothing appears
The only change is that if I use the dd() method in this field, the result from this method appears on the screen.
So its more of an initialization issue of the form itself, as the value is being passed on (observable trough xdebug). When I find more time I can check it again.
Any chance to get this fixed? I have a similar issue: entity has property "enabled" which is true by default. If add new entity from its own crud controller, Boolean Field for this property is checked by default. That's correct. But if add new entity as a new collection item in another crud controller, it's not.
Same problem here, I get a "An exception occurred while executing a query: Column '