Skip to content

Commit

Permalink
Merge pull request #1110 from City-of-Helsinki/UHF-10239
Browse files Browse the repository at this point in the history
UHF-10239 Image gallery paragraph
  • Loading branch information
annadruid authored Nov 18, 2024
2 parents c5f63f6 + e99c8cb commit 788a852
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dist/css/styles.min.css

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions hdbt.theme
Original file line number Diff line number Diff line change
Expand Up @@ -1907,3 +1907,44 @@ function hdbt_set_legacy_privacy_policy_url(array &$variables): void {
}
}
}

/**
* Implements hook_preprocess_HOOK().
*/
function hdbt_preprocess_paragraph__image_gallery_item(array &$variables): void {
// Handle image caption preprocessing.
_hdbt_preprocess_image_caption(
$variables,
'paragraph',
'field_gallery_image',
'field_gallery_image_description',
);

$paragraph = $variables['paragraph'];
$parent = $paragraph->getParentEntity();

if ($parent->hasField('field_image_gallery_ratio') && !$parent->get('field_image_gallery_ratio')->isEmpty()) {
$ratio = $parent->field_image_gallery_ratio->value;

if ($paragraph->hasField('field_gallery_image') && !$paragraph->get('field_gallery_image')->isEmpty()) {
if ($ratio == 'ratio_2_3') {
$image_style = 'image_gallery_2_3';
}
elseif ($ratio == 'ratio_3_2') {
$image_style = 'image_gallery_3_2';
}
else {
$image_style = 'image_gallery_1_1';
}

_hdbt_set_image_style(
$variables,
'paragraph',
'field_gallery_image',
$image_style
);
}

}

}
1 change: 1 addition & 0 deletions src/scss/06_components/paragraphs/__index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@import 'event-list';
@import 'hearings';
@import 'hero';
@import 'image-gallery';
@import 'image';
@import 'liftup-with-image';
@import 'list-of-links';
Expand Down
39 changes: 39 additions & 0 deletions src/scss/06_components/paragraphs/_image-gallery.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.image-gallery {
display: grid;
gap: $spacing-double;
grid-template-columns: repeat(1, 1fr);

@include breakpoint($breakpoint-s) {
grid-template-columns: repeat(2, 1fr);
}

@include breakpoint($breakpoint-l) {
grid-template-columns: repeat(3, 1fr);
}
}

.node--type-page,
.service--full,
.unit--full,
.node--type-district,
.node--type-news-article {
.components--upper .image-gallery{
@include breakpoint($breakpoint-s) {
grid-template-columns: repeat(2, 1fr);
}
}
}

.image-gallery__item-image {
overflow: hidden;
position: relative;
width: 100%;

img {
@include image-defaults($height: 100%, $width: 100%, $max-width: null);
}
}

.image-gallery__item-meta {
margin-top: $spacing-half;
}
10 changes: 10 additions & 0 deletions templates/paragraphs/paragraph--image-gallery-item.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% block paragraph %}
<div class="image-gallery__item">
<div class="image-gallery__item-image">
{{content.field_gallery_image}}
</div>
<div class="image-gallery__item-meta">
{{ gallery_image_description }}
</div>
</div>
{% endblock paragraph %}
20 changes: 20 additions & 0 deletions templates/paragraphs/paragraph--image-gallery.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% set ratio = content.field_image_gallery_ratio[0]['#markup']|replace({":": "-"}) %}

{% block paragraph %}
{% embed "@hdbt/misc/component.twig" with
{
component_classes: [ 'component--image-gallery' ],
component_title: content.field_image_gallery_title,
component_description: content.field_image_gallery_description,
component_content_class: [
'image-gallery',
'image-gallery--' ~ ratio],
}
%}
{% block component_content %}

{{ content.field_gallery_item }}

{% endblock component_content %}
{% endembed %}
{% endblock paragraph %}

0 comments on commit 788a852

Please sign in to comment.