-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from emulsify-ds/emulsif-236-convert-images-t…
…o-support-sdc EMULSIF-236: Convert Images to support SDC
- Loading branch information
Showing
4 changed files
with
118 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
$schema: https://git.drupalcode.org/project/drupal/-/raw/10.1.x/core/modules/sdc/src/metadata.schema.json | ||
|
||
name: Figure | ||
group: Components | ||
status: stable | ||
props: | ||
type: object | ||
required: | ||
- image_src | ||
- image_alt | ||
properties: | ||
output_image_tag: | ||
type: boolean | ||
title: Output image tag | ||
description: Specifies whether to output the image tag | ||
data: true | ||
image_url: | ||
type: string | ||
title: Image URL | ||
description: 'Specifies the URL that the image links to' | ||
data: '#' | ||
image_src: | ||
type: string | ||
title: Source | ||
description: 'Specifies the path to the image' | ||
data: 'https://placehold.co/1200x600' | ||
image_alt: | ||
type: string | ||
title: Alternate text | ||
description: 'Specifies an alternate text for the image' | ||
data: 'This is the alt text' | ||
image_caption: | ||
type: string | ||
title: Image caption | ||
description: 'Specifies the caption for the image' | ||
data: 'This is an image caption.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
$schema: https://git.drupalcode.org/project/drupal/-/raw/10.1.x/core/modules/sdc/src/metadata.schema.json | ||
|
||
name: Image | ||
group: Components | ||
status: stable | ||
props: | ||
type: object | ||
required: | ||
- image_src | ||
- image_alt | ||
properties: | ||
output_image_tag: | ||
type: boolean | ||
title: Output image tag | ||
description: Specifies whether to output the image tag | ||
data: true | ||
image_src: | ||
type: string | ||
title: Source | ||
description: 'Specifies the path to the image' | ||
data: 'https://placehold.co/320x180' | ||
image_alt: | ||
type: string | ||
title: Alternate text | ||
description: 'Specifies an alternate text for the image' | ||
data: 'A 16 by 9 image' | ||
image_srcset: | ||
type: string | ||
title: Source Set Attribute | ||
description: The image's srcset attribute, which defines multiple image sources for different device resolutions. | ||
data: 'https://placehold.co/320x180 320w, https://placehold.co/480x270 480w, https://placehold.co/640x360 640w, https://placehold.co/800x450 800w, https://placehold.co/960x540 960w, https://placehold.co/1120x630 1120w, https://placehold.co/1280x720 1280w, https://placehold.co/1440x810 1440w, https://placehold.co/1600x900 1600w, https://placehold.co/1760x990 1760w, https://placehold.co/1920x1080 1920w, https://placehold.co/2080x1170 2080w, https://placehold.co/2240x1260 2240w' | ||
image_sizes: | ||
type: string | ||
title: Image sizes | ||
description: 'Specifies the intended display sizes of the image' | ||
data: '100vw' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Maps properties from a given data object to a new object containing only the `data` values. | ||
* | ||
* This function iterates through the keys of the `props` object and extracts the `data` property | ||
* from each key, if it exists. The result is a new object where each key has its corresponding `data` value. | ||
* | ||
* @param {Object} props - The object containing properties with `data` fields. | ||
* @returns {Object} - A new object where each key is mapped to its `data` value from the original object. | ||
*/ | ||
export function mapDataToTwig(props) { | ||
const result = {}; | ||
|
||
for (const key in props) { | ||
if (props.hasOwnProperty(key)) { | ||
if (props[key]?.data !== undefined) { | ||
result[key] = props[key].data; | ||
} else if ( | ||
typeof props[key] === 'object' && | ||
props[key].hasOwnProperty('properties') | ||
) { | ||
result[key] = mapDataToTwig(props[key].properties); | ||
} | ||
} | ||
} | ||
|
||
return result; | ||
} |