show_choice.html.twig 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. {#
  2. This file is part of the Sonata package.
  3. (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  4. For the full copyright and license information, please view the LICENSE
  5. file that was distributed with this source code.
  6. #}
  7. {% extends 'SonataAdminBundle:CRUD:base_show_field.html.twig' %}
  8. {% block field%}
  9. {% spaceless %}
  10. {% if field_description.options.choices is defined %}
  11. {% if field_description.options.multiple is defined and field_description.options.multiple==true and value is iterable %}
  12. {% set result = '' %}
  13. {% set delimiter = field_description.options.delimiter|default(', ') %}
  14. {% for val in value %}
  15. {% if result is not empty %}
  16. {% set result = result ~ delimiter %}
  17. {% endif %}
  18. {% if field_description.options.choices[val] is defined %}
  19. {% if field_description.options.catalogue is not defined %}
  20. {% set result = result ~ field_description.options.choices[val] %}
  21. {% else %}
  22. {% set result = result ~ field_description.options.choices[val]|trans({}, field_description.options.catalogue) %}
  23. {% endif %}
  24. {% else %}
  25. {% set result = result ~ val %}
  26. {% endif %}
  27. {% endfor %}
  28. {% set value = result %}
  29. {% elseif value in field_description.options.choices|keys %}
  30. {% if field_description.options.catalogue is not defined %}
  31. {% set value = field_description.options.choices[value] %}
  32. {% else %}
  33. {% set value = field_description.options.choices[value]|trans({}, field_description.options.catalogue) %}
  34. {% endif %}
  35. {% endif %}
  36. {% endif %}
  37. {% if field_description.options.safe %}
  38. {{ value|raw }}
  39. {% else %}
  40. {{ value }}
  41. {% endif %}
  42. {% endspaceless %}
  43. {% endblock %}