Skip to content

Commit

Permalink
[ENH] don’t show currency in currencyColumn if none is set
Browse files Browse the repository at this point in the history
  • Loading branch information
n3o77 committed Feb 25, 2024
1 parent ac92e05 commit fd402fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/ColumnType/CurrencyColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public function configureOptions(OptionsResolver $resolver): void
'currency' => 'EUR',
'currency_path' => null,
'divider' => 0,
'formatOptions' => [
'fraction_digit' => 2,
],
]);

$resolver->setAllowedTypes('currency', ['string', 'null']);
Expand Down
8 changes: 7 additions & 1 deletion src/Resources/views/column_types/currency.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@

{% block column_content %}
{% set amount = value %}
{% set currency = column.type.currency(data, column.options) %}

{% if amount is not null or column.options.nullAsZero %}
{{ amount|format_currency(column.type.currency(data, column.options), column.options.formatOptions) }}
{% if currency %}
{{ amount|format_currency(currency, column.options.formatOptions) }}
{% else %}
{{ amount|format_number(column.options.formatOptions) }}
{% endif %}
{% if it_loop is defined and not it_loop.last %}
{{ type.options.implode_separator }}
{% endif %}
Expand Down

0 comments on commit fd402fe

Please sign in to comment.