Description
Description
I'd like to propose a simple way to extract the list of all entity properties that were changed upon form submission. Similar to how Doctrine computes the changeset during the flush operation, but tailored for forms mapped to entities.
Use Case:
When a form is mapped to an entity, Symfony goes through each field and updates the entity properties accordingly. However, currently, there's no straightforward way to retrieve a list of which properties were actually modified during the form submission.
Having access to this list would be incredibly useful for several reasons:
-
Granular Permission Checks: In scenarios where different user roles have permissions to edit only certain fields, being able to identify which fields are being modified allows us to enforce these permissions more effectively.
-
Audit Logging: For applications that require detailed logging of changes (e.g., admin action logs), knowing exactly which properties were changed enables us to create more informative and accurate logs.
-
Optimized Updates: By knowing the changed fields ahead of time, we can optimize database operations, perhaps updating only the necessary fields.
Current Workarounds:
While it's possible to clone the entity before form submission and manually compare the properties after submission, this approach has its drawbacks:
- It's cumbersome and adds boilerplate code to controllers.
- Deep cloning entities can be problematic, especially with complex associations.
- It doesn't leverage the fact that the form component already processes each field.
Proposed Solution:
Introduce a method or mechanism within the Symfony form handling process that provides a list of changed properties after form submission. Perhaps something like:
$changedFields = $form->getChangedFields();
or even accessing it via the data mapper:
$changedFields = $form->getDataMapper()->getChangedFields();
Example
No response