From 827e45dd475bbac4dc6e489a7b94937c4fc5a01f Mon Sep 17 00:00:00 2001 From: SvenV Date: Tue, 12 Sep 2023 11:28:43 +0200 Subject: [PATCH 1/2] SGD8-2503: Add partners block to Drupal --- .../paragraphs/paragraph--partners.html.twig | 87 ++++++++++++++++--- ...raph--field-paragraphs--partners.html.twig | 4 - ...ield--paragraph--title--partners.html.twig | 2 +- 3 files changed, 76 insertions(+), 17 deletions(-) diff --git a/templates/contrib/paragraphs/paragraph--partners.html.twig b/templates/contrib/paragraphs/paragraph--partners.html.twig index d8ca94858..7a7cc4bf3 100644 --- a/templates/contrib/paragraphs/paragraph--partners.html.twig +++ b/templates/contrib/paragraphs/paragraph--partners.html.twig @@ -40,19 +40,82 @@ */ #} -{% extends 'paragraph.html.twig' %} +{# +/** + * @file + * Default theme implementation to display a paragraph. + * + * Available variables: + * - paragraph: Full paragraph entity. + * Only method names starting with "get", "has", or "is" and a few common + * methods such as "id", "label", and "bundle" are available. For example: + * - paragraph.getCreatedTime() will return the paragraph creation timestamp. + * - paragraph.id(): The paragraph ID. + * - paragraph.bundle(): The type of the paragraph, for example, "image" or "text". + * - paragraph.getOwnerId(): The user ID of the paragraph author. + * See Drupal\paragraphs\Entity\Paragraph for a full list of public properties + * and methods for the paragraph object. + * - content: All paragraph items. Use {{ content }} to print them all, + * or print a subset such as {{ content.field_example }}. Use + * {{ content|without('field_example') }} to temporarily suppress the printing + * of a given child element. + * - attributes: HTML attributes for the containing element. + * The attributes.class element may contain one or more of the following + * classes: + * - paragraphs: The current template type (also known as a "theming hook"). + * - paragraphs--type-[type]: The current paragraphs type. For example, if the paragraph is an + * "Image" it would result in "paragraphs--type--image". Note that the machine + * name will often be in a short form of the human readable label. + * - paragraphs--view-mode--[view_mode]: The View Mode of the paragraph; for example, a + * preview would result in: "paragraphs--view-mode--preview", and + * default: "paragraphs--view-mode--default". + * - view_mode: View mode; for example, "preview" or "full". + * - logged_in: Flag for authenticated user status. Will be true when the + * current user is a logged-in member. + * - is_admin: Flag for admin user status. Will be true when the current user + * is an administrator. + * + * @see template_preprocess_paragraph() + * + * @ingroup themeable + */ +#} + +{% if content.field_paragraphs['#items']|length == 1 %} + {% set single_partner = true %} +{% endif %} + +{% set classes = [ + 'paragraph', + 'paragraph--type--' ~ paragraph.bundle|clean_class, + view_mode ? 'paragraph--view-mode--' ~ view_mode|clean_class, + not paragraph.isPublished() ? 'paragraph--unpublished', + 'partner-block', + single_partner ? 'partner__single' : 'partner__multiple', +] %} {% block paragraph %} - {% set classes = classes|merge([ - 'highlight', - 'partner-block' - ]) %} + + {% if (content.title|render|striptags|trim is not empty) or (content.field_text|render|striptags|trim is not empty) %} +
+
+ {% block title %} + {% if content.title|render|striptags|trim is not empty %} + {{ content.title }} + {% endif %} + {% endblock %} - {{ parent() }} -{% endblock %} + {% if content.field_text|render|striptags|trim is not empty %} + {{ content.field_text }} + {% endif %} +
+
+ {% endif %} -{% block content %} -
- {{ parent() }} -
-{% endblock %} +
+ {% block content %} + {{ content|without('title', 'field_text') }} + {% endblock %} +
+ +{% endblock paragraph %} diff --git a/templates/core/fields/field--paragraph--field-paragraphs--partners.html.twig b/templates/core/fields/field--paragraph--field-paragraphs--partners.html.twig index 94337343c..5c1d8c407 100644 --- a/templates/core/fields/field--paragraph--field-paragraphs--partners.html.twig +++ b/templates/core/fields/field--paragraph--field-paragraphs--partners.html.twig @@ -39,17 +39,13 @@ #} {% if items|length > 1 %} -
{% for item in items %} {{ item.content }} {% endfor %} -
{% else %} -
{% for item in items %} {{ item.content }} {% endfor %} -
{% endif %} diff --git a/templates/core/fields/field--paragraph--title--partners.html.twig b/templates/core/fields/field--paragraph--title--partners.html.twig index d06c54609..c8fbb7755 100644 --- a/templates/core/fields/field--paragraph--title--partners.html.twig +++ b/templates/core/fields/field--paragraph--title--partners.html.twig @@ -39,5 +39,5 @@ #} {% for item in items %} -

{{ item.content }}

+

{{ item.content }}

{% endfor %} From c6a21332421542f844d5b9688b42041472a985d8 Mon Sep 17 00:00:00 2001 From: SvenV Date: Tue, 19 Sep 2023 17:24:15 +0200 Subject: [PATCH 2/2] SGD8-2503: Change html for Partners block --- templates/contrib/paragraphs/paragraph--partners.html.twig | 2 +- .../field--paragraph--field-paragraphs--partners.html.twig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/contrib/paragraphs/paragraph--partners.html.twig b/templates/contrib/paragraphs/paragraph--partners.html.twig index 9e29d50bf..4c47987a6 100644 --- a/templates/contrib/paragraphs/paragraph--partners.html.twig +++ b/templates/contrib/paragraphs/paragraph--partners.html.twig @@ -49,7 +49,7 @@ view_mode ? 'paragraph--view-mode--' ~ view_mode|clean_class, not paragraph.isPublished() ? 'paragraph--unpublished', 'partner-block', - content.field_paragraphs['#is_multiple'] ? 'partner__multiple' : 'partner__single', + single_partner ? 'partner__single' : 'partner__multiple', ] %} {% block paragraph %} diff --git a/templates/core/fields/field--paragraph--field-paragraphs--partners.html.twig b/templates/core/fields/field--paragraph--field-paragraphs--partners.html.twig index 6f02aac9c..04c79d2b5 100644 --- a/templates/core/fields/field--paragraph--field-paragraphs--partners.html.twig +++ b/templates/core/fields/field--paragraph--field-paragraphs--partners.html.twig @@ -46,6 +46,6 @@ {% else %} {% for item in items %} - {{ item.content }} + {{ item.content }} {% endfor %} {% endif %}