<commit_before>{% if context.content.relation is not empty or context.contenttype.relations is defined %}

    {# Only if we have NO grouping tabs. #}
    {% if context.contenttype.groups|default is empty %}
        <hr>
    {% endif %}

    <div class="tabgrouping" data-tab="taxonomy">

        <h3>
            {{ __('Relationships') }}
            <span class="label info-pop" data-html="true" data-title="{{ __('Relationships') }}"
                data-content="{{ app.translator.trans('info.relationships', {}, 'infos') }}">{{ __('Info') }}</span>
        </h3>

{% endif %}

{# Relationships for this record #}
{% if context.contenttype.relations is defined %}

    <div class="form-group">

        {% for relcontenttype, relation in context.contenttype.relations %}

            {# Prefix #}
            {% if relation.prefix is defined and relation.prefix is not empty %}
                <div class='prefix'>
                    {{ relation.prefix|markdown }}
                </div>
            {% endif %}

            {# Relationship #}
            <fieldset>
                {# We set the 'format' for the rendering of each <option>. With fallback to a sensible default. #}
                {% set format = relation.format|default("{{ item.title|escape }} <span>(№ {{ item.id }})</span>") %}

                {{ macro.label(relation.label, relcontenttype|ucfirst, 'col-sm-4 control-label', 'relation-' ~ relcontenttype) }}
                <div class="col-sm-8">

                    {% if relation.multiple is defined and relation.multiple == 1 %}
                        <select name="relation[{{ relcontenttype }}][]" id="relation-{{ relcontenttype }}" class="wide" multiple style="width: 100%;" data-placeholder="{{ __('(none)') }}">
                    {% else %}
                        <select name="relation[{{ relcontenttype }}][]" id="relation-{{ relcontenttype }}" class="wide" style="width: 100%;" data-placeholder="{{ __('(none)') }}">
                            <option value="0">{{ __('(none)') }}</option>
                    {% endif %}
                        {% for item in listcontent(relcontenttype, relation, context.content) %}
                            {% if relcontenttype == app.request.get('relation') and item.id == app.request.get('relationid') %}
                                {% set selectedbyrelation = true %}
                            {% else %}
                                {% set selectedbyrelation = false %}
                            {% endif %}
                            <option value="{{ item.id }}"{% if item.selected or selectedbyrelation %} selected{% endif %}>
                                {{ format|twig({'item': item}) }}
                            </option>
                        {% endfor %}

                    </select>

                    <script>
                        $(function() {
                            $('#relation-{{ relcontenttype }}').select2({
                                placeholder: "{{ __('(none)') }}",
                                allowClear: true
                            });
                        });
                    </script>

                </div>
            </fieldset>

            {# Postfix #}<commit_msg>Added optgroup for relations done by groupby in contentypes.yml<commit_after>{% if context.content.relation is not empty or context.contenttype.relations is defined %}

    {# Only if we have NO grouping tabs. #}
    {% if context.contenttype.groups|default is empty %}
        <hr>
    {% endif %}

    <div class="tabgrouping" data-tab="taxonomy">

        <h3>
            {{ __('Relationships') }}
            <span class="label info-pop" data-html="true" data-title="{{ __('Relationships') }}"
                data-content="{{ app.translator.trans('info.relationships', {}, 'infos') }}">{{ __('Info') }}</span>
        </h3>

{% endif %}

{# Relationships for this record #}
{% if context.contenttype.relations is defined %}

    <div class="form-group">

        {% for relcontenttype, relation in context.contenttype.relations %}

            {# Prefix #}
            {% if relation.prefix is defined and relation.prefix is not empty %}
                <div class='prefix'>
                    {{ relation.prefix|markdown }}
                </div>
            {% endif %}

            {# Relationship #}
            <fieldset>
                {# We set the 'format' for the rendering of each <option>. With fallback to a sensible default. #}
                {% set format = relation.format|default("{{ item.title|escape }} <span>(№ {{ item.id }})</span>") %}

                {{ macro.label(relation.label, relcontenttype|ucfirst, 'col-sm-4 control-label', 'relation-' ~ relcontenttype) }}
                <div class="col-sm-8">

                    {% if relation.multiple is defined and relation.multiple == 1 %}
                        <select name="relation[{{ relcontenttype }}][]" id="relation-{{ relcontenttype }}" class="wide" multiple style="width: 100%;" data-placeholder="{{ __('(none)') }}">
                    {% else %}
                        <select name="relation[{{ relcontenttype }}][]" id="relation-{{ relcontenttype }}" class="wide" style="width: 100%;" data-placeholder="{{ __('(none)') }}">
                            <option value="0">{{ __('(none)') }}</option>
                    {% endif %}

                        {% set groupby = relation.groupby|default(false) %}
                        {% set optgroup = '' %}
                        {% for item in listcontent(relcontenttype, relation, context.content) %}
                            {% if relcontenttype == app.request.get('relation') and item.id == app.request.get('relationid') %}
                                {% set selectedbyrelation = true %}
                            {% else %}
                                {% set selectedbyrelation = false %}
                            {% endif %}
                            {% if groupby and optgroup != item[groupby] %}
                                {% if optgroup != '' %}</optgroup>{% endif %}
                                {% set optgroup = item[groupby] %}
                                <optgroup label="{{ optgroup }}">
                            {% endif %}
                            <option value="{{ item.id }}"{% if item.selected or selectedbyrelation %} selected{% endif %}>
                                {{ format|twig({'item': item}) }}
                            </option>
                        {% endfor %}
                        {% if optgroup != '' %}</optgroup>{% endif %}

                    </select>

                    <script>
                        $(function() {
                            $('#relation-{{ relcontenttype }}').select2({
                                placeholder: "{{ __('(none)') }}",
                                allowClear: true
                                {% if groupby %}, formatSelection: function (item) {
                                    return $(item.element).parent().attr('label') + ': ' + item.text;
                                }{% endif %}
                            });
                        });
                    </script>

                </div>
            </fieldset>

            {# Postfix #}
{'fraction_non_alphanumeric': 0.1522605469286794, 'fraction_numerical': 0.0035729009207090836, 'mean_word_length': 1.4187437686939182, 'pattern_counts': {'":': 0, '<': 56, '<?xml version=': 0, '>': 56, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '920127', 'n_tokens_mistral': 1941, 'n_tokens_neox': 1706, 'n_words': 412}