-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to use display_* templates without field_description (#7110)
- Loading branch information
1 parent
6d5c068
commit 7805e4a
Showing
34 changed files
with
325 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,56 @@ | ||
{# | ||
This file is part of the Sonata package. | ||
(c) Thomas Rabaix <[email protected]> | ||
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 }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{# | ||
This file is part of the Sonata package. | ||
(c) Thomas Rabaix <[email protected]> | ||
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 %} | ||
|
||
<a href="mailto:{{ value }}{% if parameters|length > 0 %}?{{- parameters|url_encode -}}{% endif %}"> | ||
{{- value -}} | ||
</a> | ||
{%- endif -%} | ||
{% endapply -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,43 @@ | ||
{# | ||
This file is part of the Sonata package. | ||
(c) Thomas Rabaix <[email protected]> | ||
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 }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,25 @@ | ||
{# | ||
This file is part of the Sonata package. | ||
(c) Thomas Rabaix <[email protected]> | ||
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 }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,55 @@ | ||
{# | ||
This file is part of the Sonata package. | ||
(c) Thomas Rabaix <[email protected]> | ||
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 %} | ||
|
||
<a | ||
href="{{ url_address }}" | ||
{%- for attribute, value in field_description.option('attributes', []) %} | ||
{%- for attribute, value in attributes|default([]) %} | ||
{{ attribute }}="{{ value|escape('html_attr') }}" | ||
{%- endfor -%} | ||
> | ||
{%- if field_description.option('safe', false) -%} | ||
{%- if safe|default(false) -%} | ||
{{- value|raw -}} | ||
{%- else -%} | ||
{{- value -}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.