Repository navigation
Read the id property of objects in ea_as_string - #7893
Merged
Merged
Conversation
phcorp
force-pushed
the
fix_as_string_id_property
branch
2 times, most recently
from
November 7, 2026 02:06
1705cc2 to
5bc6c64
Compare
The ea_as_string filter displays an object that is neither translatable nor Stringable as "<class> #<id>", reading the id only from getId(). An entity can expose its id as a public property instead (e.g. a `public private(set) ?int $id` with PHP 8.4 asymmetric visibility, or a property hook) and have no getId() method at all, so it was displayed with an object hash that changes on every request (e.g. in the headers of the CollectionField entries). The id is now read from getId() or from a public and initialized $id property. The object hash is still used when there's no id, and also when the id can't be converted to a string (null, an array or a non-Stringable object), instead of displaying "<class> #" or failing with "Object of class X could not be converted to string".
Collaborator
|
Thanks @phcorp. |
javiereguiluz
force-pushed
the
fix_as_string_id_property
branch
from
November 8, 2026 17:56
5bc6c64 to
cf36fee
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ea_as_stringshows an object that is neither translatable norStringableas<class> #<id>, and reads the id only throughgetId(). An entity can expose its id as a public property instead and have nogetId()at all, for example with PHP 8.4 asymmetric visibility:Such an entity is shown with an object hash that changes on every request, e.g. in the headers of
CollectionFieldentries.Also, when
getId()returns something that can't be cast to a string (an array, or an object that isn'tStringable), the filter fails with "Object of class X could not be converted to string". When it returnsnull, it shows<class> #.Fix
The id is read from
getId(), or else from a public, initialized$idproperty (property hooks included). The object hash is still the fallback when there's no id, or when the id isnull, an array or a non-Stringableobject.Tests
New cases in the
ea_as_stringdata provider oftests/Unit/Twig/EasyAdminTwigExtensionTest.php:$idproperty: anint, and aStringableobject$idproperty: falls back to the hashgetId()returningnull, andgetId()returning a non-Stringableobject: both fall back to the hashResults:
make tests ARGS="tests/Unit/Twig": OK (287 tests)make tests-parallel: OK (3691 tests)