Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow prefix and postfix text on relationships and taxonomies input field #2990

Merged
merged 11 commits into from
Dec 2, 2021
Merged
22 changes: 22 additions & 0 deletions templates/_macro/_macro.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,25 @@
{{- datetime|date('c') -}}
</abbr>
{% endapply %}{% endmacro %}

{#
Variables
'prefix': Is the prefix string
'id': Is a string
#}
{% macro generatePrefix(prefix, id) %}{% apply spaceless %}
{% if prefix and not (prefix starts with '<p' or prefix starts with '<span' or prefix starts with '<div') %}
<div id="{{ id }} ~ '_prefix'" class="form--helper">{{ prefix|markdown }}</div>
{% endif %}
{% endapply %}{% endmacro %}

{#
Variables
'postfix': Is the postfix string
'id': Is a string
#}
{% macro generatePostfix(postfix, id) %}{% apply spaceless %}
{% if postfix and not (postfix starts with '<p' or postfix starts with '<span' or postfix starts with '<div') %}
<div id="{{ id }} ~ '_postfix'" class="form--helper">{{ postfix|markdown }}</div>
{% endif %}
{% endapply %}{% endmacro %}
23 changes: 10 additions & 13 deletions templates/_partials/fields/_base.html.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% import '_macro/_macro.html.twig' as macro %}

{%- apply spaceless -%}

{# This template fragment is used to "extend" the different fields, used in
Expand Down Expand Up @@ -120,17 +122,6 @@
{# Set the locale #}
{% set localize = field.definition.localize|default %}

{# Set the prefix and postfix attributes #}
{% set prefix = prefix|default(field.definition.prefix|default) %}
{% if prefix and not (prefix starts with '<p' or prefix starts with '<span' or prefix starts with '<div') %}
{% set prefix = '<div id="' ~ id ~ '_prefix" class="form--helper">' ~ prefix|markdown ~ '</div>' %}
{% endif %}

{% set postfix = postfix|default(field.definition.postfix|default) %}
{% if postfix and not (postfix starts with '<p' or postfix starts with '<span' or postfix starts with '<div') %}
{% set postfix = '<div id="' ~ id ~ '_postfix" class="form--helper">' ~ postfix|markdown ~ '</div>' %}
{% endif %}

{%- endapply -%}

<!-- field "{{ label }}" (type: {{ type }}{% if variant != 'normal' %}, variant: {{ variant }}{% endif %}) -->
Expand All @@ -139,7 +130,10 @@
id="field--{{ id }}"
>

{{ prefix|raw }}
{# Print prefix #}
{% if field.definition['prefix']|default() is not empty %}
{{ macro.generatePrefix(field.definition['prefix']|default(), id) }}
{% endif %}

{% if variant == 'inline' %}<div class="row"><div class="col-3">{% endif %}

Expand All @@ -158,7 +152,10 @@

{% if variant == 'inline' %}</div></div>{% endif %}

{{ postfix|raw }}
{# Print postfix #}
{% if field.definition['postfix']|default() is not empty %}
{{ macro.generatePostfix(field.definition['postfix']|default(), id) }}
{% endif %}

{{ separator|raw }}
</div>
Expand Down
11 changes: 11 additions & 0 deletions templates/content/_relationships.html.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% import '_macro/_macro.html.twig' as macro %}

{% for contentType, relation in record.definition.relations %}

Expand All @@ -6,6 +7,11 @@

<div class="form-group is-normal">

{# Print prefix #}
{% if relation['prefix']|default() is not empty %}
{{ macro.generatePrefix(relation['prefix']|default, contentType) }}
{% endif %}

{% include '@bolt/_partials/fields/_label.html.twig' with {
'id': 'relationship-' ~ contentType,
'label': relation.label,
Expand All @@ -25,6 +31,11 @@
></editor-select>
</div>

{# Print postfix #}
{% if relation['postfix']|default() is not empty %}
{{ macro.generatePostfix(relation['postfix']|default, contentType) }}
{% endif %}

</div>

{% endfor %}
Expand Down
12 changes: 12 additions & 0 deletions templates/content/_taxonomies.html.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% import '_macro/_macro.html.twig' as macro %}

{% for taxonomy in record.definition.taxonomy %}

{% set definition = config.get('taxonomies/' ~ taxonomy) %}
Expand All @@ -8,6 +10,11 @@

<div class="form-group is-normal">

{# Print prefix #}
{% if definition['prefix']|default() is not empty %}
{{ macro.generatePrefix(definition['prefix'], taxonomy) }}
{% endif %}

{% include '@bolt/_partials/fields/_label.html.twig' with {
'id': 'taxonomy-' ~ definition.slug,
'label': definition.name,
Expand All @@ -26,6 +33,11 @@
></editor-select>
</div>

{# Print postfix #}
{% if definition['postfix']|default() is not empty %}
{{ macro.generatePostfix(definition['postfix'], taxonomy) }}
{% endif %}

</div>

{% endif %}
Expand Down