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

Issue with CollectionField and useEntryCrudForm in EasyAdminBundle #5995

Open
Mariusz225 opened this issue Oct 31, 2023 · 8 comments · May be fixed by #6000
Open

Issue with CollectionField and useEntryCrudForm in EasyAdminBundle #5995

Mariusz225 opened this issue Oct 31, 2023 · 8 comments · May be fixed by #6000

Comments

@Mariusz225
Copy link

Mariusz225 commented Oct 31, 2023

Describe the bug

  1. 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.

  2. 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

  1. Create two entities: Post and Comment, set up a OneToMany relationship between them.
  2. Use CollectionField in the PostCrudController to manage related comments.
  3. Attempt to set specific initial values for fields in Comment entity when creating a new comment.

Expected Behavior

  1. Related entity fields should be customizable in the CollectionField without the need for explicit definition in the related CRUD controller.
  2. Initial values set in the related entity should be reflected in the CollectionField when adding new related entities.

Actual Behavior

  1. Related entity fields are inherited from the current CRUD controller, leading to unexpected field inheritance in the CollectionField.
  2. 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:

obraz
obraz

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 :/

obraz
obraz

Below attached src code with example.

src.zip

@bytes-commerce
Copy link
Contributor

Maybe just copy paste the configurations in the ticket directly. 👀

@Mariusz225
Copy link
Author

Mariusz225 commented Nov 2, 2023

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.

@bytes-commerce
Copy link
Contributor

Should be easy to fix, let me have a look real quick as I am just working with the CollectionField at the moment anyway.

@bytes-commerce
Copy link
Contributor

bytes-commerce commented Nov 2, 2023

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

@Mariusz225
Copy link
Author

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.

@bytes-commerce
Copy link
Contributor

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.

@filipchuk
Copy link

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.

@nevez
Copy link

nevez commented Jul 16, 2024

Same problem here, I get a "An exception occurred while executing a query: Column '' cannot be null", field is initialized in the createEntity() method of the CRUD referenced by a CollectionField.

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

Successfully merging a pull request may close this issue.

4 participants