show_url.html.twig 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 value is empty %}
  11. &nbsp;
  12. {% else %}
  13. {% if field_description.options.url is defined %}
  14. {# target url is string #}
  15. {% set url_address = field_description.options.url %}
  16. {% elseif field_description.options.route is defined and field_description.options.route.name not in ['edit', 'show'] %}
  17. {# target url is Symfony route #}
  18. {% set parameters = field_description.options.route.parameters|default([]) %}
  19. {# route with paramter related to object ID #}
  20. {% if field_description.options.route.identifier_parameter_name is defined %}
  21. {% set parameters = parameters|merge({(field_description.options.route.identifier_parameter_name):(admin.normalizedidentifier(object))}) %}
  22. {% endif %}
  23. {% if field_description.options.route.absolute|default(false) %}
  24. {% set url_address = url(field_description.options.route.name, parameters) %}
  25. {% else %}
  26. {% set url_address = path(field_description.options.route.name, parameters) %}
  27. {% endif %}
  28. {% else %}
  29. {# value is url #}
  30. {% set url_address = value %}
  31. {% endif %}
  32. {% if field_description.options.hide_protocol|default(false) %}
  33. {% set value = value|replace({'http://': '', 'https://': ''}) %}
  34. {% endif %}
  35. <a
  36. href="{{ url_address }}"
  37. {%- for attribute, value in field_description.options.attributes|default([]) %}
  38. {{ attribute }}="{{ value|escape('html_attr') }}"
  39. {%- endfor -%}
  40. >
  41. {%- if field_description.options.safe -%}
  42. {{- value|raw -}}
  43. {%- else -%}
  44. {{- value -}}
  45. {%- endif -%}
  46. </a>
  47. {% endif %}
  48. {% endspaceless %}
  49. {% endblock %}