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

Fix incorrect object passed to the view when rendering the history compare action #6662

Merged
merged 1 commit into from
Dec 8, 2020
Merged

Fix incorrect object passed to the view when rendering the history compare action #6662

merged 1 commit into from
Dec 8, 2020

Conversation

tamcy
Copy link
Contributor

@tamcy tamcy commented Dec 7, 2020

Subject

Currently, when rendering the entity compare view in the history action, only the current (first) entity object will be passed to the view, even when it is going to render the value of the comparing (secondary) entity object. This means that the field block of the show field template will receive the first entity (the base object) along with the secondary value (value to compare) when the secondary value is going to be rendered. This can cause problem if the template does not solely rely on the value but also the object for the correct output. This PR fixes this.

I am targeting this branch, because it is backward-compatible. Note that after applying the patch, the block field_compare in template base_show_field.html.twig will assume the the existence of the object_compare variable. This may cause compatibility problem. But given that

  • SonataAdminExtension class is annotated @final, and
  • The documentation states that show_field views should extend @SonataAdmin/CRUD/base_show_field.html.twig and should not contain a field_compare block

I think it is still reasonable to say that the patch won't break BC. Otherwise I'd suggest base_show_field.html.twig to be changed to something like this:

            {% if(object_compare is defined) %}
                {% set object = object_compare %}
            {% endif %}

Changelog

### Fixed
- Incorrect object being passed to the view when rendering the history compare action

@core23 core23 added the patch label Dec 8, 2020
@VincentLanglet VincentLanglet merged commit cce4e02 into sonata-project:3.x Dec 8, 2020
@VincentLanglet
Copy link
Member

Thanks @tamcy

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

Successfully merging this pull request may close these issues.

3 participants