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

Leverage FieldDescriptionInterface::getOption() in views #7038

Merged

Conversation

phansys
Copy link
Member

@phansys phansys commented Apr 12, 2021

Subject

Leverage FieldDescriptionInterface::getOption() in views.

I am targeting this branch, because these changes respect BC.

Many usages of the Twig's default filter were removed, leveraging the argument 2 of FieldDescriptionInterface::getOption().

Changelog

### Changed
- Calls to `FieldDescriptionInterface::getOptions()` by calls to `FieldDescriptionInterface::getOption()` in views.

@jordisala1991
Copy link
Member

I think that could fix: #7029

@phansys phansys force-pushed the field_description_options_b branch from e8a89a4 to 8c0cc9e Compare April 13, 2021 00:49
@phansys phansys force-pushed the field_description_options_b branch from 8c0cc9e to bd28d86 Compare April 13, 2021 00:54
@phansys phansys added the minor label Apr 13, 2021
@phansys phansys requested a review from a team April 13, 2021 00:56
@phansys phansys marked this pull request as ready for review April 13, 2021 00:56
})) }}
{% elseif sonata_admin.field_description.options.placeholder is defined and sonata_admin.field_description.options.placeholder %}
{% elseif sonata_admin.field_description.option('placeholder') %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a general rule, should we change from:

variable.field_description.options.some_option is defined and variable.field_description.options.some_option 

to

variable.field_description.option('some_option') is not null

to be explicit?

Copy link
Member Author

@phansys phansys Apr 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, because variable.field_description.option('some_option') is not null evaluates to true when the "some_option" option is set with the value false, and in this example, the condition is trying to check if the option is holding a truthy value.

@phansys phansys requested a review from franmomu April 13, 2021 10:05
Copy link
Member

@franmomu franmomu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add a hasOption method, that would make things clearer IMO (but that's another issue).

@VincentLanglet VincentLanglet merged commit 63fd17f into sonata-project:3.x Apr 13, 2021
@phansys phansys deleted the field_description_options_b branch April 13, 2021 13:38
@VincentLanglet
Copy link
Member

@phansys This is a BC-break

Before, using

{%- include '@SonataAdmin/CRUD/display_boolean.html.twig' -%}

in a non-fielddescriptions context could work, since there was a is defined check every where.
Now it throw an error.

Also, before passgin fieldDescription: { options: { ... }} could work. Now it doesn't.

I think it could be great having the display_ template to work without the need of fieldDescriptions.
Usage could be

include '@SonataAdmin/CRUD/display_boolean.html.twig' with (inverse: fieldDescriptions.getOption('inverse', false))

And the code

{% if field_description.option('inverse', false) ? not value : value %}

would be changed to

{% if inverse|default(false) ? not value : value %}

The current bugfix could be

{% if field_description.option('inverse', false)|default(false) ? not value : value %}

The BC-way to introduce the feature could be

{% if inverse|field_description.option('inverse', false)|default(false) ? not value : value %}

WDYT ?

@phansys
Copy link
Member Author

phansys commented Apr 23, 2021

@phansys This is a BC-break

I've experiencing the same issue with one of my custom views, but I dismissed the problem since I think we haven't a BC promise around our internal templates.
I think we could make some changes to avoid this, but I don't understand the syntax around your last snippet: inverse|field_description. Would field_description interpreted as a Twig filter?

@VincentLanglet
Copy link
Member

I meant

Inverse|default(fielddescription.option(inverse))|default(false)

@phansys
Copy link
Member Author

phansys commented Apr 24, 2021

LGTM.

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.

None yet

4 participants