-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
[AdminListBundle] Display associations when using viewAction() #2564
base: master
Are you sure you want to change the base?
[AdminListBundle] Display associations when using viewAction() #2564
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @, your PR needs some changes
- This PR seems to need a milestone of a minor release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @, your PR passed all our requirements.
Thank you for contributing!
$accessor = PropertyAccess::createPropertyAccessor(); | ||
foreach ($MetaData->fieldNames as $value) { | ||
foreach ($metaData->getReflectionProperties() as $value => $reflectionProperty) { | ||
$fields[$value] = $accessor->getValue($helper, $value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could add a check here to see if the object has a __toString
method, otherwise skip the property. Something like
if (\is_object($value) && !method_exists($value, '__toString')) {
continue;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would not return the expected results. The value could be returned by $accessor->getValue($helper, $value);
without having __toString()
implemented in the entity. Adding your suggestion would cause no values to be displayed.
I've just tested this with an entity that has relations without having __toString()
implemented. It caused an error. But the error came from the method getStringValue()
from AbstractAdminListConfigurator
, because it just tries to access getName()
on every entity in the collection (eventhough that most likely does not exist).
I get that you cant add this if it breaks rendering objects which don't have the __toString method. I think at this point it should only break for anyone who has overwritten the getStringValue()
method, while not calling parent::getStringValue()
and not taking in account the $result
could be an instance of PersistentCollection
. I don't know what the policy is that you guys have on this, but if this is not good enough then you can close this pull request :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JZuidema We can't add this if it breaks rendering of objects which don't have the __toString method. See my inline comment for a possible fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @, your PR needs some changes
- This PR seems to need a milestone of a minor release.
$MetaData->fieldNames
returns a list of regular property names, it does not return names of association mappings. This causes all associations not to be shown when viewing an entity in the adminlist.$metaData->getReflectionProperties()
returns all properties. Also addedkey | trans
to be able to translate the names of the properties when viewing the data.I'd like to add that this change could potentially cause an exception for anyone who has uses view option in an admin list, when their entity has assocations and those entities havent implemented __toString()