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

When "percent" field is NULL, show non breaking space instead of 0 #6632

Merged
merged 3 commits into from
Dec 2, 2020
Merged

Conversation

willemverspyck
Copy link
Contributor

Subject

When using this code:

    protected function configureListFields(ListMapper $listMapper): void
    {
        $listMapper
            ->add('rate', TemplateRegistry::TYPE_PERCENT);
    }

And the value of "rate" is NULL, the current return value is "0 %". I think the value must be " " for NULL and "0 %" for 0. Also return " " when currency is NULL.

Same change for configureShowFields.

I am targeting this branch, because it's BC.

Changelog

### Changed
Twig templates: "list_percent", "show_percent", "list_currency" and "show_currency"

@willemverspyck willemverspyck marked this pull request as ready for review November 27, 2020 08:08
Comment on lines +13 to +18
{%- if value is null -%}
 
{%- else -%}
{% set value = value * 100 %}
{{ value }} %
{%- endif -%}
Copy link
Member

Choose a reason for hiding this comment

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

Why a nbsp ?

Suggested change
{%- if value is null -%}
 
{%- else -%}
{% set value = value * 100 %}
{{ value }} %
{%- endif -%}
{%- if value is not null -%}
{{ value * 100 }} %
{%- endif -%}

Should be enough ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Years ago &nbsp was necessary to prevent problems with cells, but I don't think they are needed anymore. I used the same code as "display_datetime", "display_date" and "display_time" where also &nbsp is displayed when value is empty. Do you want me to change those too?

Copy link
Member

Choose a reason for hiding this comment

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

If we don't need them, let's avoid them indeed.
Elsewhere, but if it's for consistency, I won't block this PR.

Comment on lines +13 to +17
{%- if value is null -%}
 
{%- else -%}
{{ field_description.options.currency }} {{ value }}
{%- endif -%}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
{%- if value is null -%}
 
{%- else -%}
{{ field_description.options.currency }} {{ value }}
{%- endif -%}
{%- if value is not null -%}
{{ field_description.options.currency }} {{ value }}
{%- endif -%}

@VincentLanglet VincentLanglet requested review from a team, phansys, core23 and franmomu November 30, 2020 08:48
@VincentLanglet VincentLanglet merged commit afe64e6 into sonata-project:3.x Dec 2, 2020
@VincentLanglet
Copy link
Member

Thanks @willemverspyck

@franmomu franmomu added the minor label Dec 2, 2020
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