list_choice.html.twig 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 admin.getTemplate('base_list_field') %}
  8. {% set is_editable =
  9. field_description.options.editable is defined and
  10. field_description.options.editable and
  11. admin.isGranted('EDIT', object)
  12. %}
  13. {% set x_editable_type = field_description.type|sonata_xeditable_type %}
  14. {% if is_editable and x_editable_type %}
  15. {% block field_span_attributes %}
  16. {% spaceless %}
  17. {{ parent() }}
  18. data-source="{{ field_description|sonata_xeditable_choices|json_encode }}"
  19. {% endspaceless %}
  20. {% endblock %}
  21. {% endif %}
  22. {% block field %}
  23. {% spaceless %}
  24. {% if field_description.options.choices is defined %}
  25. {% if field_description.options.multiple is defined and field_description.options.multiple==true and value is iterable %}
  26. {% set result = '' %}
  27. {% set delimiter = field_description.options.delimiter|default(', ') %}
  28. {% for val in value %}
  29. {% if result is not empty %}
  30. {% set result = result ~ delimiter %}
  31. {% endif %}
  32. {% if field_description.options.choices[val] is defined %}
  33. {% if field_description.options.catalogue is not defined %}
  34. {% set result = result ~ field_description.options.choices[val] %}
  35. {% else %}
  36. {% set result = result ~ field_description.options.choices[val]|trans({}, field_description.options.catalogue) %}
  37. {% endif %}
  38. {% else %}
  39. {% set result = result ~ val %}
  40. {% endif %}
  41. {% endfor %}
  42. {% set value = result %}
  43. {% elseif value in field_description.options.choices|keys %}
  44. {% if field_description.options.catalogue is not defined %}
  45. {% set value = field_description.options.choices[value] %}
  46. {% else %}
  47. {% set value = field_description.options.choices[value]|trans({}, field_description.options.catalogue) %}
  48. {% endif %}
  49. {% endif %}
  50. {% endif %}
  51. {{ value }}
  52. {% endspaceless %}
  53. {% endblock %}