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

[AdminListBundle] Display associations when using viewAction() #2564

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

JZuidema
Copy link
Contributor

@JZuidema JZuidema commented Oct 9, 2019

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Fixed tickets

$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 added key | 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()

Copy link

@ProfessorKuma ProfessorKuma left a 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.

@ProfessorKuma ProfessorKuma added this to the 5.4.0 milestone Oct 9, 2019
Copy link

@ProfessorKuma ProfessorKuma left a 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);
Copy link
Member

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;
}

Copy link
Contributor Author

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

Copy link
Member

@acrobat acrobat left a 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

@acrobat acrobat modified the milestones: 5.4.0, 5.5.0 Jan 10, 2020
@acrobat acrobat removed this from the 5.5.0 milestone Mar 17, 2020
Copy link

@ProfessorKuma ProfessorKuma left a 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.

@ProfessorKuma ProfessorKuma added this to the 5.6.0 milestone Mar 30, 2020
@acrobat acrobat removed this from the 5.6.0 milestone Jun 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants