{% extends 'bootstrap_4_layout.html.twig' %}

{#
  block is extended in order to:
  - add required symbol
  - we translate here to avoid having to have html suffix in translate key
#}
{% block form_label -%}
  {% if form.vars.required|default(false) == true %}
    {% if label is not empty %}
      {% if translation_domain is same as(false) %}
        {% set label %}{{ label|raw }}<span class="required-field">*</span>{% endset %}
      {% else %}
        {% set label %}{{ label|trans(label_translation_parameters, translation_domain)|raw }}<span class="required-field">*</span>{% endset %}
      {% endif %}
      {% set label_html = true %}
      {% set translation_domain = false %}
    {% endif %}
  {% endif %}
  {{ parent() }}
{%- endblock form_label %}

{% block aa_admin_collection_row %}
  {% set row_attr = form.vars.row_attr %}
  {% set row_attr = row_attr|merge({class: row_attr.class|default('') ~ ' aa-admin-collection-wrap'}) %}
  {{ block('form_row') }}
{% endblock %}

{% block aa_admin_collection_widget %}
  {% set attr = form.vars.attr %}
  {% set attr = attr|merge({class: attr.class|default('') ~ ' aa-admin-collection'}) %}
  {{ form_errors(form) }}
  {# basic prototype handling #}
  {% if prototype is defined and not prototype.rendered %}
    {% set attr = attr|merge({'data-prototype': form_row(prototype) }) %}
  {% endif %}
  {% set subAttr = {
    'data-form-allow-add': form.vars.allow_add ? '1':'0',
    'data-form-allow-delete': form.vars.allow_delete ? '1':'0',
    'data-form-allow-sort': form.vars.allow_sort ? '1':'0',
    'data-form-entry-delete-label': 'aa_admin.collection.delete_entry_label'|trans({}, 'aa_admin'),
    'data-form-required': form.vars.required,
    'data-form-index': form.vars.value|length()|default(0),
  } %}
  {% set attr = attr|merge(subAttr) %}
  {{ form_widget(form, {attr: attr}) }}
  {% if form.vars.allow_add %}
    <button class="btn btn-secondary aa-admin-collection-add" tabindex="-1">
      + {{ 'aa_admin.collection.add_entry_label'|trans({}, 'aa_admin') }}
    </button>
  {% endif %}
{% endblock %}