From 7805e4af7999656f86b44c24e58e03fd68d14b50 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sat, 24 Apr 2021 22:59:36 +0200 Subject: [PATCH] Allow to use display_* templates without field_description (#7110) --- .../views/CRUD/_email_link.html.twig | 3 +- .../views/CRUD/display_boolean.html.twig | 7 +- .../views/CRUD/display_choice.html.twig | 77 +++++++++++-------- .../views/CRUD/display_currency.html.twig | 7 +- .../views/CRUD/display_date.html.twig | 8 +- .../views/CRUD/display_datetime.html.twig | 10 ++- .../views/CRUD/display_email.html.twig | 38 +++++++++ .../views/CRUD/display_html.html.twig | 28 ++++++- .../views/CRUD/display_time.html.twig | 8 +- .../views/CRUD/display_trans.html.twig | 23 +++++- .../views/CRUD/display_url.html.twig | 45 +++++++---- .../CRUD/history_revision_timestamp.html.twig | 6 +- .../views/CRUD/list_boolean.html.twig | 5 +- .../views/CRUD/list_choice.html.twig | 9 ++- .../views/CRUD/list_currency.html.twig | 5 +- src/Resources/views/CRUD/list_date.html.twig | 6 +- .../views/CRUD/list_datetime.html.twig | 6 +- src/Resources/views/CRUD/list_email.html.twig | 7 +- src/Resources/views/CRUD/list_html.html.twig | 6 +- .../views/CRUD/list_percent.html.twig | 2 +- src/Resources/views/CRUD/list_time.html.twig | 6 +- src/Resources/views/CRUD/list_trans.html.twig | 7 +- src/Resources/views/CRUD/list_url.html.twig | 15 +++- .../views/CRUD/show_boolean.html.twig | 5 +- .../views/CRUD/show_choice.html.twig | 9 ++- .../views/CRUD/show_currency.html.twig | 5 +- src/Resources/views/CRUD/show_date.html.twig | 6 +- .../views/CRUD/show_datetime.html.twig | 6 +- src/Resources/views/CRUD/show_email.html.twig | 7 +- src/Resources/views/CRUD/show_html.html.twig | 6 +- .../views/CRUD/show_percent.html.twig | 2 +- src/Resources/views/CRUD/show_time.html.twig | 6 +- src/Resources/views/CRUD/show_trans.html.twig | 7 +- src/Resources/views/CRUD/show_url.html.twig | 15 +++- 34 files changed, 325 insertions(+), 83 deletions(-) create mode 100644 src/Resources/views/CRUD/display_email.html.twig diff --git a/src/Resources/views/CRUD/_email_link.html.twig b/src/Resources/views/CRUD/_email_link.html.twig index 3343db2169..4dfddd582f 100644 --- a/src/Resources/views/CRUD/_email_link.html.twig +++ b/src/Resources/views/CRUD/_email_link.html.twig @@ -1,4 +1,5 @@ - +{# NEXT_MAJOR: Remove this template #} +{% deprecated 'The "_email_link.html.twig" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.' %} {%- if value is empty -%}   {%- elseif field_description.option('as_string', false) -%} diff --git a/src/Resources/views/CRUD/display_boolean.html.twig b/src/Resources/views/CRUD/display_boolean.html.twig index 8cffe837a2..ea89102480 100644 --- a/src/Resources/views/CRUD/display_boolean.html.twig +++ b/src/Resources/views/CRUD/display_boolean.html.twig @@ -10,13 +10,18 @@ file that was distributed with this source code. #} {%- apply spaceless %} + {# NEXT_MAJOR: Remove this BC-layer #} + {% if field_description is defined %} + {% set inverse = inverse|default(field_description.option('inverse', false)) %} + {% endif %} + {% if value %} {% set text = 'label_type_yes'|trans({}, 'SonataAdminBundle') %} {% else %} {% set text = 'label_type_no'|trans({}, 'SonataAdminBundle') %} {% endif %} - {% if field_description.option('inverse', false) ? not value : value %} + {% if inverse|default(false) ? not value : value %} {% set class = 'label-success' %} {% else %} {% set class = 'label-danger' %} diff --git a/src/Resources/views/CRUD/display_choice.html.twig b/src/Resources/views/CRUD/display_choice.html.twig index e9c45ff6aa..318d903825 100644 --- a/src/Resources/views/CRUD/display_choice.html.twig +++ b/src/Resources/views/CRUD/display_choice.html.twig @@ -1,39 +1,56 @@ +{# + +This file is part of the Sonata package. + +(c) Thomas Rabaix + +For the full copyright and license information, please view the LICENSE +file that was distributed with this source code. + +#} + {%- apply spaceless %} - {% if field_description.option('choices') is not null %} - {% if field_description.option('multiple', false) and value is iterable %} - - {% set result = '' %} - {% set delimiter = field_description.option('delimiter', ', ') %} - - {% for val in value %} - {% if result is not empty %} - {% set result = result ~ delimiter %} - {% endif %} - - {% if field_description.option('choices')[val] is defined %} - {% set choice = field_description.option('choices')[val] %} - {% else %} - {% set choice = val %} - {% endif %} - {% if field_description.option('catalogue') %} - {% set result = result ~ choice|trans({}, field_description.option('catalogue')) %} - {% else %} - {% set result = result ~ choice %} - {% endif %} - {% endfor %} - - {% set value = result %} - - {% elseif value in field_description.option('choices')|keys %} - {% if field_description.option('catalogue') is null %} - {% set value = field_description.option('choices')[value] %} + {# NEXT_MAJOR: Remove this BC-layer #} + {% if field_description is defined %} + {% set choices = choices|default(field_description.option('choices')) %} + {% set multiple = multiple|default(field_description.option('multiple', false)) %} + {% set delimiter = delimiter|default(field_description.option('delimiter', ', ')) %} + {% set translation_domain = translation_domain|default(field_description.option('catalogue')) %} + {% set safe = safe|default(field_description.option('safe', false)) %} + {% endif %} + + {% set choices = choices|default([]) %} + {% if multiple|default(false) and value is iterable %} + + {% set result = '' %} + {% for val in value %} + {% if result is not empty %} + {% set result = result ~ delimiter|default(', ') %} + {% endif %} + + {% if choices[val] is defined %} + {% set choice = choices[val] %} {% else %} - {% set value = field_description.option('choices')[value]|trans({}, field_description.option('catalogue')) %} + {% set choice = val %} {% endif %} + {% if translation_domain|default(null) is null %} + {% set result = result ~ choice %} + {% else %} + {% set result = result ~ choice|trans({}, translation_domain) %} + {% endif %} + {% endfor %} + + {% set value = result %} + + {% elseif value in choices|keys %} + {% if translation_domain|default(null) is null %} + {% set value = choices[value] %} + {% else %} + {% set value = choices[value]|trans({}, translation_domain) %} {% endif %} {% endif %} - {% if field_description.option('safe', false) %} + {% if safe|default(false) %} {{ value|raw }} {% else %} {{ value }} diff --git a/src/Resources/views/CRUD/display_currency.html.twig b/src/Resources/views/CRUD/display_currency.html.twig index 7fcf42057d..122bfbe281 100644 --- a/src/Resources/views/CRUD/display_currency.html.twig +++ b/src/Resources/views/CRUD/display_currency.html.twig @@ -10,9 +10,14 @@ file that was distributed with this source code. #} {%- apply spaceless %} + {# NEXT_MAJOR: Remove this BC-layer #} + {% if field_description is defined %} + {% set currency = currency|default(field_description.option('currency')) %} + {% endif %} + {%- if value is null -%}   {%- else -%} - {{ field_description.option('currency') }} {{ value }} + {{ currency|default(null) }} {{ value }} {%- endif -%} {% endapply -%} diff --git a/src/Resources/views/CRUD/display_date.html.twig b/src/Resources/views/CRUD/display_date.html.twig index 1bef315b73..d3436df24a 100644 --- a/src/Resources/views/CRUD/display_date.html.twig +++ b/src/Resources/views/CRUD/display_date.html.twig @@ -10,11 +10,17 @@ file that was distributed with this source code. #} {%- apply spaceless %} + {# NEXT_MAJOR: Remove this BC-layer #} + {% if field_description is defined %} + {% set format = format|default(field_description.option('format', 'F j, Y')) %} + {% set timezone = timezone|default(field_description.option('timezone')) %} + {% endif %} + {%- if value is empty -%}   {%- else -%} {%- endif -%} {% endapply -%} diff --git a/src/Resources/views/CRUD/display_datetime.html.twig b/src/Resources/views/CRUD/display_datetime.html.twig index 69b860bc8c..9c98fc3e16 100644 --- a/src/Resources/views/CRUD/display_datetime.html.twig +++ b/src/Resources/views/CRUD/display_datetime.html.twig @@ -10,13 +10,17 @@ file that was distributed with this source code. #} {%- apply spaceless %} + {# NEXT_MAJOR: Remove this BC-layer #} + {% if field_description is defined %} + {% set format = format|default(field_description.option('format')) %} + {% set timezone = timezone|default(field_description.option('timezone')) %} + {% endif %} + {%- if value is empty -%}   {%- else -%} - {% set format = field_description.option('format') %} - {% set timezone = field_description.option('timezone') %} {%- endif -%} {% endapply -%} diff --git a/src/Resources/views/CRUD/display_email.html.twig b/src/Resources/views/CRUD/display_email.html.twig new file mode 100644 index 0000000000..c15bf59ed4 --- /dev/null +++ b/src/Resources/views/CRUD/display_email.html.twig @@ -0,0 +1,38 @@ +{# + +This file is part of the Sonata package. + +(c) Thomas Rabaix + +For the full copyright and license information, please view the LICENSE +file that was distributed with this source code. + +#} + +{%- apply spaceless %} + {# NEXT_MAJOR: Remove this BC-layer #} + {% if field_description is defined %} + {% set as_string = format|default(field_description.option('as_string')) %} + {% set subject = subject|default(field_description.option('subject')) %} + {% set body = body|default(field_description.option('body')) %} + {% endif %} + + {%- if value is empty -%} +   + {%- elseif as_string|default(false) -%} + {{ value }} + {%- else -%} + {% set parameters = {} %} + + {% if subject|default(null) is not empty %} + {% set parameters = parameters|merge({'subject': subject}) %} + {% endif %} + {% if body|default(null) is not empty %} + {% set parameters = parameters|merge({'body': body}) %} + {% endif %} + + + {{- value -}} + + {%- endif -%} +{% endapply -%} diff --git a/src/Resources/views/CRUD/display_html.html.twig b/src/Resources/views/CRUD/display_html.html.twig index 9a48ed3a5a..63ee572d2a 100644 --- a/src/Resources/views/CRUD/display_html.html.twig +++ b/src/Resources/views/CRUD/display_html.html.twig @@ -1,21 +1,43 @@ +{# + +This file is part of the Sonata package. + +(c) Thomas Rabaix + +For the full copyright and license information, please view the LICENSE +file that was distributed with this source code. + +#} + {%- apply spaceless %} + {# NEXT_MAJOR: Remove this BC-layer #} + {% if field_description is defined %} + {% set truncate = truncate|default(field_description.option('truncate')) %} + {% set strip = strip|default(field_description.option('strip', false)) %} + {% endif %} + {%- if value is empty -%}   {% else %} - {%- if field_description.option('truncate') -%} - {% set truncate = field_description.option('truncate') %} + {%- if truncate|default(null) -%} {% set length = truncate.length|default(30) %} + {# NEXT_MAJOR: Remove this #} {% if truncate.preserve is defined %} {% deprecated 'The "truncate.preserve" option is deprecated since sonata-project/admin-bundle 3.65, to be removed in 4.0. Use "truncate.cut" instead.' %} {% endif %} + {# NEXT_MAJOR: Remove this and uncomment the following line #} {% set cut = truncate.cut is defined ? truncate.cut : (truncate.preserve is defined ? truncate.preserve != true : true) %} + {# {% set cut = truncate.cut|default(true) %} #} + {# NEXT_MAJOR: Remove this #} {% if truncate.separator is defined %} {% deprecated 'The "truncate.separator" option is deprecated since sonata-project/admin-bundle 3.65, to be removed in 4.0. Use "truncate.ellipsis" instead.' %} {% endif %} + {# NEXT_MAJOR: Remove this and uncomment the following line #} {% set ellipsis = truncate.ellipsis is defined ? truncate.ellipsis : (truncate.separator is defined ? truncate.separator : '...') %} + {# {% set ellipsis = truncate.ellipsis|default('...') %} #} {{ value|striptags|u.truncate(length, ellipsis, cut)|raw }} {%- else -%} - {%- if field_description.option('strip', false) -%} + {%- if strip|default(false) -%} {% set value = value|striptags %} {%- endif -%} {{ value|raw }} diff --git a/src/Resources/views/CRUD/display_time.html.twig b/src/Resources/views/CRUD/display_time.html.twig index 2691426841..f52b3609bb 100644 --- a/src/Resources/views/CRUD/display_time.html.twig +++ b/src/Resources/views/CRUD/display_time.html.twig @@ -10,11 +10,17 @@ file that was distributed with this source code. #} {%- apply spaceless %} + {# NEXT_MAJOR: Remove this BC-layer #} + {% if field_description is defined %} + {% set format = format|default(field_description.option('format', 'H:i:s')) %} + {% set timezone = timezone|default(field_description.option('timezone')) %} + {% endif %} + {%- if value is empty -%}   {%- else -%} {%- endif -%} {% endapply -%} diff --git a/src/Resources/views/CRUD/display_trans.html.twig b/src/Resources/views/CRUD/display_trans.html.twig index 3f84585805..cc3ddab121 100644 --- a/src/Resources/views/CRUD/display_trans.html.twig +++ b/src/Resources/views/CRUD/display_trans.html.twig @@ -1,10 +1,25 @@ +{# + +This file is part of the Sonata package. + +(c) Thomas Rabaix + +For the full copyright and license information, please view the LICENSE +file that was distributed with this source code. + +#} + {%- apply spaceless %} - {% set value_format = field_description.option('format', '%s') %} - {% set translation_domain = field_description.option('catalogue', admin.translationDomain) %} + {# NEXT_MAJOR: Remove this BC-layer #} + {% if field_description is defined %} + {% set value_format = value_format|default(field_description.option('format', '%s')) %} + {% set translation_domain = translation_domain|default(field_description.option('catalogue', admin.translationDomain)) %} + {% set safe = safe|default(field_description.option('safe', false)) %} + {% endif %} - {% set value = value_format|format(value)|trans({}, translation_domain) %} + {% set value = value_format|default('%s')|format(value)|trans({}, translation_domain|default('messages')) %} - {% if field_description.option('safe', false) %} + {% if safe|default(false) %} {{ value|raw }} {% else %} {{ value }} diff --git a/src/Resources/views/CRUD/display_url.html.twig b/src/Resources/views/CRUD/display_url.html.twig index c66fe070f3..011ed2555c 100644 --- a/src/Resources/views/CRUD/display_url.html.twig +++ b/src/Resources/views/CRUD/display_url.html.twig @@ -1,40 +1,55 @@ +{# + +This file is part of the Sonata package. + +(c) Thomas Rabaix + +For the full copyright and license information, please view the LICENSE +file that was distributed with this source code. + +#} + {%- apply spaceless %} + {# NEXT_MAJOR: Remove this BC-layer #} + {% if field_description is defined %} + {% set url = url|default(field_description.option('url')) %} + {% set route = route|default(field_description.option('route')) %} + {% set hide_protocol = hide_protocol|default(field_description.option('hide_protocol', false)) %} + {% set attributes = attributes|default(field_description.option('attributes', [])) %} + {% set safe = safe|default(field_description.option('safe', false)) %} + {% endif %} + {% if value is empty %}   {% else %} - {% if field_description.option('url') %} + {% if url|default(null) %} {# target url is string #} - {% set url_address = field_description.option('url') %} - {% elseif field_description.option('route') is not null and field_description.option('route').name not in ['edit', 'show'] %} + {% set url_address = url %} + {% elseif route|default(null) is not null %} {# target url is Symfony route #} - {% set parameters = field_description.option('route').parameters|default([]) %} - - {# route with paramter related to object ID #} - {% if field_description.option('route').identifier_parameter_name is defined %} - {% set parameters = parameters|merge({(field_description.option('route').identifier_parameter_name):(admin.normalizedidentifier(object))}) %} - {% endif %} + {% set parameters = route.parameters|default([]) %} - {% if field_description.option('route').absolute|default(false) %} - {% set url_address = url(field_description.option('route').name, parameters) %} + {% if route.absolute|default(false) %} + {% set url_address = url(route.name, parameters) %} {% else %} - {% set url_address = path(field_description.option('route').name, parameters) %} + {% set url_address = path(route.name, parameters) %} {% endif %} {% else %} {# value is url #} {% set url_address = value %} {% endif %} - {% if field_description.option('hide_protocol', false) %} + {% if hide_protocol|default(false) %} {% set value = value|replace({'http://': '', 'https://': ''}) %} {% endif %} - {%- if field_description.option('safe', false) -%} + {%- if safe|default(false) -%} {{- value|raw -}} {%- else -%} {{- value -}} diff --git a/src/Resources/views/CRUD/history_revision_timestamp.html.twig b/src/Resources/views/CRUD/history_revision_timestamp.html.twig index 8b5b258b8f..83f6ae53cf 100644 --- a/src/Resources/views/CRUD/history_revision_timestamp.html.twig +++ b/src/Resources/views/CRUD/history_revision_timestamp.html.twig @@ -9,4 +9,8 @@ file that was distributed with this source code. #} -{%- include '@SonataAdmin/CRUD/display_datetime.html.twig' with { value: revision.timestamp } -%} +{%- include '@SonataAdmin/CRUD/display_datetime.html.twig' with { + value: revision.timestamp, + format: field_description.option('format'), + timezone: field_description.option('timezone'), +} only -%} diff --git a/src/Resources/views/CRUD/list_boolean.html.twig b/src/Resources/views/CRUD/list_boolean.html.twig index 781bafd335..dc492efe9a 100644 --- a/src/Resources/views/CRUD/list_boolean.html.twig +++ b/src/Resources/views/CRUD/list_boolean.html.twig @@ -24,5 +24,8 @@ file that was distributed with this source code. {% endblock %} {% block field %} - {%- include '@SonataAdmin/CRUD/display_boolean.html.twig' -%} + {%- include '@SonataAdmin/CRUD/display_boolean.html.twig' with { + value: value, + inverse: field_description.option('inverse'), + } only -%} {% endblock %} diff --git a/src/Resources/views/CRUD/list_choice.html.twig b/src/Resources/views/CRUD/list_choice.html.twig index cf41c86e95..dfb320e2eb 100644 --- a/src/Resources/views/CRUD/list_choice.html.twig +++ b/src/Resources/views/CRUD/list_choice.html.twig @@ -27,5 +27,12 @@ file that was distributed with this source code. {% endblock %} {% block field %} - {%- include '@SonataAdmin/CRUD/display_choice.html.twig' -%} + {%- include '@SonataAdmin/CRUD/display_choice.html.twig' with { + value: value, + choices: field_description.option('choices'), + multiple: field_description.option('multiple'), + delimiter: field_description.option('delimiter'), + translation_domain: field_description.option('catalogue'), + safe: field_description.option('safe'), + } only -%} {% endblock %} diff --git a/src/Resources/views/CRUD/list_currency.html.twig b/src/Resources/views/CRUD/list_currency.html.twig index c71766b451..3f13ff7cd0 100644 --- a/src/Resources/views/CRUD/list_currency.html.twig +++ b/src/Resources/views/CRUD/list_currency.html.twig @@ -12,5 +12,8 @@ file that was distributed with this source code. {% extends get_admin_template('base_list_field', admin.code) %} {% block field %} - {%- include '@SonataAdmin/CRUD/display_currency.html.twig' -%} + {%- include '@SonataAdmin/CRUD/display_currency.html.twig' with { + value: value, + currency: field_description.option('currency'), + } only -%} {% endblock %} diff --git a/src/Resources/views/CRUD/list_date.html.twig b/src/Resources/views/CRUD/list_date.html.twig index af69a93c3a..1665584d78 100644 --- a/src/Resources/views/CRUD/list_date.html.twig +++ b/src/Resources/views/CRUD/list_date.html.twig @@ -12,5 +12,9 @@ file that was distributed with this source code. {% extends get_admin_template('base_list_field', admin.code) %} {% block field %} - {%- include '@SonataAdmin/CRUD/display_date.html.twig' -%} + {%- include '@SonataAdmin/CRUD/display_date.html.twig' with { + value: value, + format: field_description.option('format'), + timezone: field_description.option('timezone'), + } only -%} {% endblock %} diff --git a/src/Resources/views/CRUD/list_datetime.html.twig b/src/Resources/views/CRUD/list_datetime.html.twig index 62e6d25d21..8ae60f84fa 100644 --- a/src/Resources/views/CRUD/list_datetime.html.twig +++ b/src/Resources/views/CRUD/list_datetime.html.twig @@ -12,5 +12,9 @@ file that was distributed with this source code. {% extends get_admin_template('base_list_field', admin.code) %} {% block field %} - {%- include '@SonataAdmin/CRUD/display_datetime.html.twig' -%} + {%- include '@SonataAdmin/CRUD/display_datetime.html.twig' with { + value: value, + format: field_description.option('format'), + timezone: field_description.option('timezone'), + } only -%} {% endblock %} diff --git a/src/Resources/views/CRUD/list_email.html.twig b/src/Resources/views/CRUD/list_email.html.twig index 77991e7b91..f2241313b2 100644 --- a/src/Resources/views/CRUD/list_email.html.twig +++ b/src/Resources/views/CRUD/list_email.html.twig @@ -12,5 +12,10 @@ file that was distributed with this source code. {% extends get_admin_template('base_list_field', admin.code) %} {% block field %} - {% include '@SonataAdmin/CRUD/_email_link.html.twig' %} + {% include '@SonataAdmin/CRUD/display_email.html.twig' with { + value: value, + as_string: field_description.option('as_string'), + subject: field_description.option('subject'), + body: field_description.option('body'), + } only %} {% endblock %} diff --git a/src/Resources/views/CRUD/list_html.html.twig b/src/Resources/views/CRUD/list_html.html.twig index d96867ecc9..1966bb5f44 100644 --- a/src/Resources/views/CRUD/list_html.html.twig +++ b/src/Resources/views/CRUD/list_html.html.twig @@ -1,5 +1,9 @@ {% extends get_admin_template('base_list_field', admin.code) %} {% block field %} - {%- include '@SonataAdmin/CRUD/display_html.html.twig' -%} + {%- include '@SonataAdmin/CRUD/display_html.html.twig' with { + value: value, + truncate: field_description.option('truncate'), + strip: field_description.option('strip'), + } only -%} {% endblock %} diff --git a/src/Resources/views/CRUD/list_percent.html.twig b/src/Resources/views/CRUD/list_percent.html.twig index ece4476dcc..2569e6c763 100644 --- a/src/Resources/views/CRUD/list_percent.html.twig +++ b/src/Resources/views/CRUD/list_percent.html.twig @@ -12,5 +12,5 @@ file that was distributed with this source code. {% extends get_admin_template('base_list_field', admin.code) %} {% block field %} - {%- include '@SonataAdmin/CRUD/display_percent.html.twig' -%} + {%- include '@SonataAdmin/CRUD/display_percent.html.twig' with { value: value } only -%} {% endblock %} diff --git a/src/Resources/views/CRUD/list_time.html.twig b/src/Resources/views/CRUD/list_time.html.twig index 9b254d38e1..bdfb96e48c 100644 --- a/src/Resources/views/CRUD/list_time.html.twig +++ b/src/Resources/views/CRUD/list_time.html.twig @@ -12,5 +12,9 @@ file that was distributed with this source code. {% extends get_admin_template('base_list_field', admin.code) %} {% block field %} - {%- include '@SonataAdmin/CRUD/display_time.html.twig' -%} + {%- include '@SonataAdmin/CRUD/display_time.html.twig' with { + value: value, + format: field_description.option('format'), + timezone: field_description.option('timezone'), + } only -%} {% endblock %} diff --git a/src/Resources/views/CRUD/list_trans.html.twig b/src/Resources/views/CRUD/list_trans.html.twig index 20c5d2e18e..598e5887fa 100644 --- a/src/Resources/views/CRUD/list_trans.html.twig +++ b/src/Resources/views/CRUD/list_trans.html.twig @@ -12,5 +12,10 @@ file that was distributed with this source code. {% extends get_admin_template('base_list_field', admin.code) %} {% block field %} - {%- include '@SonataAdmin/CRUD/display_trans.html.twig' -%} + {%- include '@SonataAdmin/CRUD/display_trans.html.twig' with { + value: value, + value_format: field_description.option('format'), + translation_domain: field_description.option('catalogue', admin.translationDomain), + safe: field_description.option('safe'), + } only -%} {% endblock %} diff --git a/src/Resources/views/CRUD/list_url.html.twig b/src/Resources/views/CRUD/list_url.html.twig index 7c2cd814ac..5ab4f3ef8a 100644 --- a/src/Resources/views/CRUD/list_url.html.twig +++ b/src/Resources/views/CRUD/list_url.html.twig @@ -12,5 +12,18 @@ file that was distributed with this source code. {% extends get_admin_template('base_list_field', admin.code) %} {% block field %} - {%- include '@SonataAdmin/CRUD/display_url.html.twig' -%} + {%- set route = field_description.option('route') -%} + {%- if route is not null and route.identifier_parameter_name is defined -%} + {%- set newParameters = {(route.identifier_parameter_name):(admin.normalizedidentifier(object))} -%} + {%- set route = route|merge({parameters: route.parameters|default([])|merge(newParameters)}) -%} + {%- endif -%} + + {%- include '@SonataAdmin/CRUD/display_url.html.twig' with { + value: value, + url: field_description.option('url'), + route: route, + hide_protocol: field_description.option('hide_protocol'), + attributes: field_description.option('attributes'), + safe: field_description.option('safe'), + } only -%} {% endblock %} diff --git a/src/Resources/views/CRUD/show_boolean.html.twig b/src/Resources/views/CRUD/show_boolean.html.twig index 54e29c4456..9bbef0ffc9 100644 --- a/src/Resources/views/CRUD/show_boolean.html.twig +++ b/src/Resources/views/CRUD/show_boolean.html.twig @@ -12,5 +12,8 @@ file that was distributed with this source code. {% extends '@SonataAdmin/CRUD/base_show_field.html.twig' %} {% block field %} - {%- include '@SonataAdmin/CRUD/display_boolean.html.twig' -%} + {%- include '@SonataAdmin/CRUD/display_boolean.html.twig' with { + value: value, + inverse: field_description.option('inverse'), + } only -%} {% endblock %} diff --git a/src/Resources/views/CRUD/show_choice.html.twig b/src/Resources/views/CRUD/show_choice.html.twig index d56027a628..85b579bfe4 100644 --- a/src/Resources/views/CRUD/show_choice.html.twig +++ b/src/Resources/views/CRUD/show_choice.html.twig @@ -11,5 +11,12 @@ file that was distributed with this source code. {% extends '@SonataAdmin/CRUD/base_show_field.html.twig' %} {% block field %} - {%- include '@SonataAdmin/CRUD/display_choice.html.twig' -%} + {%- include '@SonataAdmin/CRUD/display_choice.html.twig' with { + value: value, + choices: field_description.option('choices'), + multiple: field_description.option('multiple'), + delimiter: field_description.option('delimiter'), + translation_domain: field_description.option('catalogue'), + safe: field_description.option('safe'), + } only -%} {% endblock %} diff --git a/src/Resources/views/CRUD/show_currency.html.twig b/src/Resources/views/CRUD/show_currency.html.twig index 68c8d260cb..3d97ae0e12 100644 --- a/src/Resources/views/CRUD/show_currency.html.twig +++ b/src/Resources/views/CRUD/show_currency.html.twig @@ -12,5 +12,8 @@ file that was distributed with this source code. {% extends '@SonataAdmin/CRUD/base_show_field.html.twig' %} {% block field %} - {%- include '@SonataAdmin/CRUD/display_currency.html.twig' -%} + {%- include '@SonataAdmin/CRUD/display_currency.html.twig' with { + value: value, + currency: field_description.option('currency'), + } only -%} {% endblock %} diff --git a/src/Resources/views/CRUD/show_date.html.twig b/src/Resources/views/CRUD/show_date.html.twig index d8378c0adf..f062b0af6a 100644 --- a/src/Resources/views/CRUD/show_date.html.twig +++ b/src/Resources/views/CRUD/show_date.html.twig @@ -12,5 +12,9 @@ file that was distributed with this source code. {% extends '@SonataAdmin/CRUD/base_show_field.html.twig' %} {% block field %} - {%- include '@SonataAdmin/CRUD/display_date.html.twig' -%} + {%- include '@SonataAdmin/CRUD/display_date.html.twig' with { + value: value, + format: field_description.option('format'), + timezone: field_description.option('timezone'), + } only -%} {% endblock %} diff --git a/src/Resources/views/CRUD/show_datetime.html.twig b/src/Resources/views/CRUD/show_datetime.html.twig index 5d93c1e22e..bf8fa9d29e 100644 --- a/src/Resources/views/CRUD/show_datetime.html.twig +++ b/src/Resources/views/CRUD/show_datetime.html.twig @@ -12,5 +12,9 @@ file that was distributed with this source code. {% extends '@SonataAdmin/CRUD/base_show_field.html.twig' %} {% block field %} - {%- include '@SonataAdmin/CRUD/display_datetime.html.twig' -%} + {%- include '@SonataAdmin/CRUD/display_datetime.html.twig' with { + value: value, + format: field_description.option('format'), + timezone: field_description.option('timezone'), + } only -%} {% endblock %} diff --git a/src/Resources/views/CRUD/show_email.html.twig b/src/Resources/views/CRUD/show_email.html.twig index d3c5efaeee..729ff55df4 100644 --- a/src/Resources/views/CRUD/show_email.html.twig +++ b/src/Resources/views/CRUD/show_email.html.twig @@ -1,5 +1,10 @@ {% extends '@SonataAdmin/CRUD/base_show_field.html.twig' %} {% block field %} - {% include '@SonataAdmin/CRUD/_email_link.html.twig' %} + {% include '@SonataAdmin/CRUD/display_email.html.twig' with { + value: value, + as_string: field_description.option('as_string'), + subject: field_description.option('subject'), + body: field_description.option('body'), + } only %} {% endblock %} diff --git a/src/Resources/views/CRUD/show_html.html.twig b/src/Resources/views/CRUD/show_html.html.twig index 6151d3d63f..0e0a896240 100644 --- a/src/Resources/views/CRUD/show_html.html.twig +++ b/src/Resources/views/CRUD/show_html.html.twig @@ -1,5 +1,9 @@ {% extends '@SonataAdmin/CRUD/base_show_field.html.twig' %} {% block field %} - {%- include '@SonataAdmin/CRUD/display_html.html.twig' -%} + {%- include '@SonataAdmin/CRUD/display_html.html.twig' with { + value: value, + truncate: field_description.option('truncate'), + strip: field_description.option('strip'), + } only -%} {% endblock %} diff --git a/src/Resources/views/CRUD/show_percent.html.twig b/src/Resources/views/CRUD/show_percent.html.twig index 23d2419a3b..c2ed94ad1a 100644 --- a/src/Resources/views/CRUD/show_percent.html.twig +++ b/src/Resources/views/CRUD/show_percent.html.twig @@ -12,5 +12,5 @@ file that was distributed with this source code. {% extends '@SonataAdmin/CRUD/base_show_field.html.twig' %} {% block field %} - {%- include '@SonataAdmin/CRUD/display_percent.html.twig' -%} + {%- include '@SonataAdmin/CRUD/display_percent.html.twig' with { value: value } only -%} {% endblock %} diff --git a/src/Resources/views/CRUD/show_time.html.twig b/src/Resources/views/CRUD/show_time.html.twig index dae18f5e3e..aaa618e979 100644 --- a/src/Resources/views/CRUD/show_time.html.twig +++ b/src/Resources/views/CRUD/show_time.html.twig @@ -12,5 +12,9 @@ file that was distributed with this source code. {% extends '@SonataAdmin/CRUD/base_show_field.html.twig' %} {% block field %} - {%- include '@SonataAdmin/CRUD/display_time.html.twig' -%} + {%- include '@SonataAdmin/CRUD/display_time.html.twig' with { + value: value, + format: field_description.option('format'), + timezone: field_description.option('timezone'), + } only -%} {% endblock %} diff --git a/src/Resources/views/CRUD/show_trans.html.twig b/src/Resources/views/CRUD/show_trans.html.twig index 0dc15436d1..f8aed9f682 100644 --- a/src/Resources/views/CRUD/show_trans.html.twig +++ b/src/Resources/views/CRUD/show_trans.html.twig @@ -11,5 +11,10 @@ file that was distributed with this source code. {% extends '@SonataAdmin/CRUD/base_show_field.html.twig' %} {% block field %} - {%- include '@SonataAdmin/CRUD/display_trans.html.twig' -%} + {%- include '@SonataAdmin/CRUD/display_trans.html.twig' with { + value: value, + value_format: field_description.option('format'), + translation_domain: field_description.option('catalogue', admin.translationDomain), + safe: field_description.option('safe'), + } only -%} {% endblock %} diff --git a/src/Resources/views/CRUD/show_url.html.twig b/src/Resources/views/CRUD/show_url.html.twig index 0dbc542198..8b4c51cbeb 100644 --- a/src/Resources/views/CRUD/show_url.html.twig +++ b/src/Resources/views/CRUD/show_url.html.twig @@ -12,5 +12,18 @@ file that was distributed with this source code. {% extends '@SonataAdmin/CRUD/base_show_field.html.twig' %} {% block field %} - {%- include '@SonataAdmin/CRUD/display_url.html.twig' -%} + {%- set route = field_description.option('route') -%} + {%- if route is not null and route.identifier_parameter_name is defined -%} + {%- set newParameters = {(route.identifier_parameter_name):(admin.normalizedidentifier(object))} -%} + {%- set route = route|merge({parameters: route.parameters|default([])|merge(newParameters)}) -%} + {%- endif -%} + + {%- include '@SonataAdmin/CRUD/display_url.html.twig' with { + value: value, + url: field_description.option('url'), + route: route, + hide_protocol: field_description.option('hide_protocol'), + attributes: field_description.option('attributes'), + safe: field_description.option('safe'), + } only -%} {% endblock %}