From 93442780d49520af01d37cabe535cb610382b3ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?benjamin=20melan=C3=A7on?= Date: Tue, 18 Dec 2018 12:26:06 -0500 Subject: [PATCH] With much tribulation, accept title paragraphs into the case study teaser fold --- ...ragraph--field-subtitle--preview.html.twig | 6 +++ .../layout/node--case-study--teaser.html.twig | 24 +++++++----- .../paragraph--title--preview.html.twig | 37 +++++++++++++++++++ 3 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 agaric/templates/field/field--paragraph--field-subtitle--preview.html.twig create mode 100644 agaric/templates/paragraph/paragraph--title--preview.html.twig diff --git a/agaric/templates/field/field--paragraph--field-subtitle--preview.html.twig b/agaric/templates/field/field--paragraph--field-subtitle--preview.html.twig new file mode 100644 index 0000000..5bfc270 --- /dev/null +++ b/agaric/templates/field/field--paragraph--field-subtitle--preview.html.twig @@ -0,0 +1,6 @@ +{# Overrides field--field-subtitle.html.twig for case study teasers (which use + the title paragraph 'preview' view mode). #} + +{% for item in items %} + {{ item.content}} +{% endfor %} diff --git a/agaric/templates/layout/node--case-study--teaser.html.twig b/agaric/templates/layout/node--case-study--teaser.html.twig index e28ceb1..a9375fd 100644 --- a/agaric/templates/layout/node--case-study--teaser.html.twig +++ b/agaric/templates/layout/node--case-study--teaser.html.twig @@ -1,23 +1,27 @@ -{# Somewhat ironically, we take away the ability for case studies to be - represented by their title paragraph. Because we *don't* use the title - paragraph for the main listings on the front page and the /work page (both of - which use the tile view mode, which uses only set regular fields), the use of - the title paragraph for search results (and anywhere else we use teasers) - would be a surprise— the summary field, while also not used on the listing - pages, is at least consistently used across multiple content types. - - See agaric/templates/layout/node--teaser.html.twig for variables. -#} +{# See agaric/templates/layout/node--teaser.html.twig for variables. #}
+ +{% set has_title_paragraph = false %} +{% if content.field_body_paragraph %} + {% for i, paragraph in content.field_body_paragraph if i|first != '#' %} + {% if content.field_body_paragraph['#items'][i].entity.type.0.entity.id == 'title' %} + {% set has_title_paragraph = true %} + {{ paragraph }} + {% endif %} + {% endfor %} +{% endif %} + +{% if not has_title_paragraph %} {{ content.field_image }} {% if node.bundle == 'case_study' and content.field_case_study_subtitle is not empty %} {% endif %} +{% endif %}

{{ label }}

diff --git a/agaric/templates/paragraph/paragraph--title--preview.html.twig b/agaric/templates/paragraph/paragraph--title--preview.html.twig new file mode 100644 index 0000000..8350587 --- /dev/null +++ b/agaric/templates/paragraph/paragraph--title--preview.html.twig @@ -0,0 +1,37 @@ +{# +/** + * The paragraph preview view mode is used in the node teaser view mode. + * + * @see agaric/templates/paragraph/paragraph--title.html.twig for variables. + */ +#} +{% + set classes = [ + 'hero', + not paragraph.isPublished() ? 'paragraph--unpublished' + ] +%} +{% if paragraph.field_style_color is not empty %} + {% set classes = classes|merge(['is-'~paragraph.field_style_color.value]) %} +{% endif %} +{% if paragraph.field_style_titlebar.value == false %} + {% set classes = classes|merge(['hero-project']) %} +{% endif %} +{% if paragraph.field_style_classes is not empty %} + {% set styles=[] %} + {% for style in paragraph.field_style_classes %} + {% set styles = styles|merge([style.value]) %} + {% endfor %} + {% set classes = classes|merge(styles) %} +{% endif %} + +{% if paragraph.field_style_titlebar.value == true and paragraph.field_image is not empty %} + {% set attributes = attributes.setAttribute('data-headerbg', 'transparent').setAttribute('style', 'background-image: url('~file_url(paragraph.field_image.entity.uri.value)~')') %} +{% endif %} + +{% block paragraph %} + {% block content %} + {{ content.field_image }} + + {% endblock %} +{% endblock paragraph %}