Skip to content

Commit

Permalink
Merge pull request #840 from City-of-Helsinki/UHF-10239
Browse files Browse the repository at this point in the history
UHF-10239: Adds image gallery paragraph
  • Loading branch information
annadruid authored Nov 18, 2024
2 parents 18e44be + 9b076df commit 45e879f
Show file tree
Hide file tree
Showing 69 changed files with 1,214 additions and 4 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions modules/hdbt_admin_tools/hdbt_admin_tools.module
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,14 @@ function hdbt_admin_tools_entity_bundle_field_info_alter(&$fields, EntityTypeInt
) {
$fields['field_has_hero']->addConstraint('Hero', []);
}

if ($entity_type->id() === 'paragraph' && $bundle == 'image_gallery') {
// Add constraint to check if image gallery has two gallery items.
if (array_key_exists('field_gallery_item', $fields)) {
$fields['field_gallery_item']->addConstraint('ImageGallery', []);
}
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Drupal\hdbt_admin_tools\Plugin\Validation\Constraint;

use Symfony\Component\Validator\Constraint;

/**
* Checks that the image gallery has at least two items.
*
* @Constraint(
* id = "ImageGallery",
* label = @Translation("There should be at least two gallery items.", context = "Validation"),
* type = "entity:paragraph"
* )
*/
class ImageGalleryConstraint extends Constraint {

/**
* Message shown for the Image gallery paragraph.
*
* @var string
*/
public string $galleryItemRequired = 'Image gallery paragraph should have at least two items.';

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Drupal\hdbt_admin_tools\Plugin\Validation\Constraint;

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;

/**
* Validates the Image Gallery constraint.
*/
class ImageGalleryConstraintValidator extends ConstraintValidator {

/**
* {@inheritdoc}
*/
public function validate(mixed $value, Constraint $constraint): void {
assert($constraint instanceof ImageGalleryConstraint);
$parent = $value->getEntity();

if ($value->getName() !== 'field_gallery_item') {
return;
}

if (
$parent &&
$parent->hasField('field_gallery_item') &&
$parent->get('field_gallery_item')->count() < 2
) {
$this->context->addViolation($constraint->galleryItemRequired);
}
}

}
6 changes: 6 additions & 0 deletions modules/hdbt_admin_tools/translations/fi.po
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,9 @@ msgstr "Tekstialue (merkkimäärälaskuri)"

msgid "Textfield (character counter)"
msgstr "Tekstikenttä (merkkimäärälaskuri)"

msgid "Image gallery paragraph should have at least two items."
msgstr "Kuvagalleriassa tulisi olla vähintään kaksi kuvaa."

msgid "Image is mandatory with the selected Hero design."
msgstr "Kuva on pakollinen valitun designin kanssa."
6 changes: 6 additions & 0 deletions modules/hdbt_admin_tools/translations/sv.po
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,9 @@ msgstr "Uppdatera användarlösenord"

msgid "Hero paragraph is mandatory if the Hero checkbox has been selected. Either unselect the checkbox or create the hero paragraph by clicking the Add Hero button."
msgstr "Hero paragraph är obligatoriskt om kryssrutan Hero har markerats. Avmarkera antingen kryssrutan eller skapa hero paragraph genom att klicka på knappen Lägg till Hero"

msgid "Image gallery paragraph should have at least two items."
msgstr "Det bör finnas minst två bilder i bildgalleriet"

msgid "Image is mandatory with the selected Hero design."
msgstr "Bild är obligatorisk med den valda Hero-designen."
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
uuid: 74ef3c22-d7ea-4cb1-8aab-01ba6b79bde5
langcode: en
status: true
dependencies:
module:
- focal_point
- image_style_quality
name: 0.7_1086w_1630h_LQ
label: 0.7_1086w_1630h_LQ
effects:
1c1da0f4-bb6a-4f11-88eb-8cd33a8e0da2:
uuid: 1c1da0f4-bb6a-4f11-88eb-8cd33a8e0da2
id: focal_point_scale_and_crop
weight: 1
data:
width: 1086
height: 1630
crop_type: focal_point
c319bca0-92f7-4467-a5ec-1b902ce2be1b:
uuid: c319bca0-92f7-4467-a5ec-1b902ce2be1b
id: image_style_quality
weight: 2
data:
quality: 65
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
uuid: f0276d08-9181-4923-9b87-49e9bf5ee5f4
langcode: en
status: true
dependencies:
module:
- focal_point
name: 0.7_352w_572h
label: 0.7_352w_572h
effects:
11ff7a5b-af0b-4eac-a4a3-7bc3b9ac6188:
uuid: 11ff7a5b-af0b-4eac-a4a3-7bc3b9ac6188
id: focal_point_scale_and_crop
weight: 1
data:
width: 352
height: 572
crop_type: focal_point
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
uuid: 9ec716c1-6f6d-4d08-971f-a9d9230e43b7
langcode: en
status: true
dependencies:
module:
- focal_point
name: 0.7_414w_621h
label: 0.7_414w_621h
effects:
dc8a6ee8-839c-4972-9eb8-5df5305dc75d:
uuid: dc8a6ee8-839c-4972-9eb8-5df5305dc75d
id: focal_point_scale_and_crop
weight: 1
data:
width: 414
height: 621
crop_type: focal_point
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
uuid: 6ff8a4a5-849c-4f94-8f22-1eb670793bdc
langcode: en
status: true
dependencies:
module:
- focal_point
name: 0.7_543w_815h
label: 0.7_543w_815h
effects:
6535b34f-21c8-4005-8561-d1936245e319:
uuid: 6535b34f-21c8-4005-8561-d1936245e319
id: focal_point_scale_and_crop
weight: 1
data:
width: 543
height: 815
crop_type: focal_point
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
uuid: 19aa2c22-c3e9-47cd-b767-9fca520ae4ba
langcode: en
status: true
dependencies:
module:
- focal_point
- image_style_quality
name: 0.7_704w_1144h_LQ
label: 0.7_704w_1144h_LQ
effects:
289822b3-1d38-43a4-a18e-0344b4ef9161:
uuid: 289822b3-1d38-43a4-a18e-0344b4ef9161
id: focal_point_scale_and_crop
weight: 1
data:
width: 704
height: 1144
crop_type: focal_point
c5118eb7-9ad5-4756-9515-d6358c38bd75:
uuid: c5118eb7-9ad5-4756-9515-d6358c38bd75
id: image_style_quality
weight: 2
data:
quality: 65
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
uuid: 5ebc2957-c7ca-4606-ba96-49486e6630e4
langcode: en
status: true
dependencies:
module:
- focal_point
- image_style_quality
name: 0.7_828w_1242h_LQ
label: 0.7_828w_1242h_LQ
effects:
fb181588-37f9-4269-ae4e-7c93d76ffebe:
uuid: fb181588-37f9-4269-ae4e-7c93d76ffebe
id: focal_point_scale_and_crop
weight: 1
data:
width: 828
height: 1242
crop_type: focal_point
a3284e2a-d636-4454-b7b6-3958d1db2b35:
uuid: a3284e2a-d636-4454-b7b6-3958d1db2b35
id: image_style_quality
weight: 2
data:
quality: 65
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
uuid: 9f76056d-d05c-40e9-9455-9caf237c2229
langcode: en
status: true
dependencies:
module:
- focal_point
- image_style_quality
name: 1_1086w_1086h_LQ
label: 1_1086w_1086h_LQ
effects:
3fe5b5a5-6dcd-4410-865d-22d39e20ae22:
uuid: 3fe5b5a5-6dcd-4410-865d-22d39e20ae22
id: focal_point_scale_and_crop
weight: 1
data:
width: 1086
height: 1086
crop_type: focal_point
348c0fc5-7317-49a8-9a52-934e77165825:
uuid: 348c0fc5-7317-49a8-9a52-934e77165825
id: image_style_quality
weight: 2
data:
quality: 65
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
uuid: 0f96fcb7-856c-4d80-9a22-b1e88f44ca2b
langcode: en
status: true
dependencies:
module:
- focal_point
name: 1_414w_414h
label: 1_414w_414h
effects:
9ef8198f-6739-4a26-b0d7-157e42648cc4:
uuid: 9ef8198f-6739-4a26-b0d7-157e42648cc4
id: focal_point_scale_and_crop
weight: 1
data:
width: 414
height: 414
crop_type: focal_point
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
uuid: ca8cb2c4-7e3c-4a4a-ae75-9520f628f369
langcode: en
status: true
dependencies:
module:
- focal_point
name: 1_543w_543h
label: 1_543w_543h
effects:
ed62a58f-6f7b-47ff-b8c9-3574fb9abeba:
uuid: ed62a58f-6f7b-47ff-b8c9-3574fb9abeba
id: focal_point_scale_and_crop
weight: 1
data:
width: 543
height: 543
crop_type: focal_point
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
uuid: d0a56f46-9d91-47a8-9269-57fda40b75ed
langcode: en
status: true
dependencies:
module:
- focal_point
- image_style_quality
name: 1_828w_828h_LQ
label: 1_828w_828h_LQ
effects:
c4554106-234a-4d04-a6cf-c7ae4f8886dd:
uuid: c4554106-234a-4d04-a6cf-c7ae4f8886dd
id: focal_point_scale_and_crop
weight: 1
data:
width: 828
height: 828
crop_type: focal_point
ee011418-cb33-48a5-af34-10bfac5b3e64:
uuid: ee011418-cb33-48a5-af34-10bfac5b3e64
id: image_style_quality
weight: 2
data:
quality: 65
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
uuid: c0fef26d-9cc5-4756-b247-5a9c3f7b4550
langcode: en
status: true
dependencies:
config:
- image.style.1_1086w_1086h_LQ
- image.style.1_414w_414h
- image.style.1_543w_543h
- image.style.1_828w_828h_LQ
module:
- helfi_image_styles
id: image_gallery_1_1
label: 'Image gallery 1:1'
image_style_mappings:
-
image_mapping_type: image_style
image_mapping: 1_414w_414h
breakpoint_id: helfi_image_styles.m
multiplier: 1x
-
image_mapping_type: image_style
image_mapping: 1_828w_828h_LQ
breakpoint_id: helfi_image_styles.m
multiplier: 2x
-
image_mapping_type: image_style
image_mapping: 1_543w_543h
breakpoint_id: helfi_image_styles.xs
multiplier: 1x
-
image_mapping_type: image_style
image_mapping: 1_1086w_1086h_LQ
breakpoint_id: helfi_image_styles.xs
multiplier: 2x
breakpoint_group: helfi_image_styles
fallback_image_style: 1_414w_414h
Loading

0 comments on commit 45e879f

Please sign in to comment.