{#

This file is part of the Sonata package.

(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}

{%- apply spaceless %}
    {% if value is empty %}
        &nbsp;
    {% else %}
        {% if url|default(null) %}
            {# target url is string #}
            {% set url_address = url %}
        {% elseif route|default(null) is not null and route.name not in ['edit', 'show'] %}
            {# target url is Symfony route #}
            {% set parameters = route.parameters|default([]) %}

            {% if route.absolute|default(false) %}
                {% set url_address = url(route.name, parameters) %}
            {% else %}
                {% set url_address = path(route.name, parameters) %}
            {% endif %}
        {% else %}
            {# value is url #}
            {% set url_address = value %}
        {% endif %}

        {% if hide_protocol|default(false) %}
            {% set value = value|replace({'http://': '', 'https://': ''}) %}
        {% endif %}

        <a
            href="{{ url_address }}"
        {%- for attribute, value in attributes|default([]) %}
            {{ attribute }}="{{ value|escape('html_attr') }}"
        {%- endfor -%}
        >
        {%- if safe|default(false) -%}
            {{- value|raw -}}
        {%- else -%}
            {{- value -}}
        {%- endif -%}
        </a>
    {% endif %}
{% endapply -%}
