<commit_before>{#=== INIT ===========================================================================================================#}

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

{# Use option groups #}
{% set groupby = relation.groupby|default(false) %}

{# Build the select options array #}
{% set options = [] %}
{% for item in listcontent(relcontenttype, relation, context.content) %}
    {% set selectedbyrelation = relcontenttype == app.request.get('relation') and
                                item.id == app.request.get('relationid') %}

    {% set options = options|merge([{
        value:     item.id,
        text:      format|twig({'item': item}),
        group:     groupby ? item.values[groupby]|default(false) : false,
        selected:  item.selected or selectedbyrelation,
    }]) %}
{% endfor %}

{# BUIC options #}
{% set buico_select = {
    'name':      'relation[' ~ relcontenttype ~ '][]',
    'id':        'relation-' ~ relcontenttype,
    'multiple':  relation.multiple is defined and relation.multiple == 1,
    'options':   options,
    'clear':     true,
} %}

{#=== FIELDSET =======================================================================================================#}

{% extends '_base/_fieldset.twig' %}

{% block fieldset_type 'relationship' %}

{% block fieldset_label_text  relation.label|default(relcontenttype|ucfirst) %}
{% block fieldset_label_class 'col-sm-4' %}

{% block fieldset_controls %}
    <div class="col-sm-8"><commit_msg>Update relationship Twig for entity changes<commit_after>{#=== INIT ===========================================================================================================#}

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

{# Use option groups #}
{% set groupby = relation.groupby|default(false) %}

{# Build the select options array #}
{% set options = [] %}

{% for item in context.content.relation[relcontenttype] %}
    {% set options = options|merge([{
        value:     item.id,
        text:      format|twig({'title': item.get('title'), 'id': item.get('id')}),
        group:     groupby ? item.values[groupby]|default(false) : false,
        selected:  true,
    }]) %}
{% endfor %}

{# BUIC options #}
{% set buico_select = {
    'name':      'relation[' ~ relcontenttype ~ '][]',
    'id':        'relation-' ~ relcontenttype,
    'multiple':  relation.multiple is defined and relation.multiple == 1,
    'options':   options,
    'clear':     true,
} %}

{#=== FIELDSET =======================================================================================================#}

{% extends '_base/_fieldset.twig' %}

{% block fieldset_type 'relationship' %}

{% block fieldset_label_text  relation.label|default(relcontenttype|ucfirst) %}
{% block fieldset_label_class 'col-sm-4' %}

{% block fieldset_controls %}
    <div class="col-sm-8">
{'fraction_non_alphanumeric': 0.2840727736993297, 'fraction_numerical': 0.001915097350781998, 'mean_word_length': 4.095934959349593, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6737702', 'n_tokens_mistral': 942, 'n_tokens_neox': 866, 'n_words': 203}