With much tribulation, accept title paragraphs into the case study teaser fold

This commit is contained in:
benjamin melançon 2018-12-18 12:26:06 -05:00
parent e9de7bb0b8
commit 93442780d4
3 changed files with 57 additions and 10 deletions

View file

@ -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 %}

View file

@ -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. #}
<a class="teaser media content" href="{{ url }}">
<div class="media-left">
{% 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 %}
<p class="byline is-mono">
{{ content.field_case_study_subtitle }}
</p>
{% endif %}
{% endif %}
</div>
<div class="media-content content">
<h3 class="title is-5">{{ label }}</h3>

View file

@ -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 }}
<p class="byline is-mono">{{ content.field_subtitle }}</p>
{% endblock %}
{% endblock paragraph %}