{#
 # For the full copyright and license information, please view the
 # docs/licenses/LICENSE.txt file that was distributed with this source code.
 #}

{% set class = 'btn tooltip-link js-link-row-action' %}

{% if attributes.class is defined %}
  {% set class = class ~ ' ' ~ attributes.class %}
{% endif %}

  {% set route_params = {(action.options.route_param_name): (record[action.options.route_param_field])} %}
  {% set extra_route_params = action.options.extra_route_params %}

  {% for name, field in extra_route_params %}
    {% set route_params = route_params|merge({(name): (record[field] ?? field)}) %}
  {% endfor %}

<a class="{{ class }} grid-{{ action.name|lower|replace({' ': '-'}) }}-row-link"
   href="{{ path(action.options.route, route_params) }}"
   data-confirm-message="{{ action.options.confirm_message }}"
  {% if attributes.tooltip_name %}
    data-toggle="pstooltip"
    data-placement="top"
    data-original-title="{{ action.name }}"
  {% endif %}
  data-clickable-row="{{ action.options.clickable_row|default(false) }}"
  {% if action.options.target is not empty %}target="{{ action.options.target }}"{% endif %}
  {# Add all attributes which are not class #}
  {%- for attrname, attrvalue in action.options.attr -%}
    {% if attrname != 'class' %}
      {{- ' ' -}}
      {% if attrvalue is formview %}
        {{- attrname }}="{{ form_row(attrvalue)|e('html_attr') }}"
      {% elseif attrvalue is form %}
      {{- attrname }}="{{ form_row(attrvalue.createView())|e('html_attr') }}"
      {% else %}
        {{- attrname }}="{{ attrvalue }}"
      {% endif %}
    {% endif %}
  {%- endfor -%}
>
  {% if action.icon is not empty %}
    <i class="material-icons">{{ action.icon }}</i>
  {% endif %}
  {% if not attributes.tooltip_name %}
    {{ action.name }}
  {% endif %}
</a>
