Skip to content

Commit

Permalink
update sample content, image from page
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Sep 4, 2023
1 parent 5f0eadc commit 2a032e9
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class ImageV2Impl extends ImageV3Impl implements LinkMixin {
public static final String RESOURCE_TYPE = "wcm-io/wcm/core/components/image/v2/image";

@Override
protected Media buildMedia(boolean altFromAsset) {
protected Media buildMedia(boolean altFromAsset, boolean imageFromPageImage) {
return HandlerUnwrapper.get(mediaHandler, resource)
// disable dynamic media support as it is not compatible with the "src-pattern" concept
.dynamicMediaDisabled(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ private void activate() {
lazyThreshold = currentStyle.get(PN_DESIGN_LAZY_THRESHOLD, 0);
isDecorative = properties.get(PN_IS_DECORATIVE, currentStyle.get(PN_IS_DECORATIVE, false));
boolean altFromAsset = properties.get(PN_ALT_VALUE_FROM_DAM, currentStyle.get(PN_ALT_VALUE_FROM_DAM, true));
boolean imageFromPageImage = properties.get(PN_IMAGE_FROM_PAGE_IMAGE, true);

// resolve link - decorative images have no link and no alt text by definition
if (isDecorative) {
Expand All @@ -146,7 +147,7 @@ private void activate() {
}

// resolve media and properties from DAM asset
media = buildMedia(altFromAsset);
media = buildMedia(altFromAsset, imageFromPageImage);

if (media.isValid() && !media.getRendition().isImage()) {
// no image asset selected (cannot be rendered) - set to invalid
Expand All @@ -161,10 +162,11 @@ private void activate() {

}

protected Media buildMedia(boolean altFromAsset) {
protected Media buildMedia(boolean altFromAsset, boolean imageFromPageImage) {
ComponentFeatureImageResolver imageResolver = new ComponentFeatureImageResolver(resource, getCurrentPage(), currentStyle, mediaHandler)
.targetPage(getCurrentPage())
.altValueFromDam(altFromAsset)
.imageFromPageImage(imageFromPageImage)
.mediaHandlerProperty(PROP_CSS_CLASS, "cmp-image__image")
.mediaHandlerProperty("itemprop", "contentUrl");
String imageTitle = title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class ComponentFeatureImageResolver {
private final MediaHandler mediaHandler;
private final Map<String, Object> mediaHandlerProperties = new HashMap<>();

private final boolean imageFromPageImage;
private boolean imageFromPageImage;
private final boolean altValueFromPageImage;
private boolean altValueFromDam;
private final boolean isDecorative;
Expand Down Expand Up @@ -105,6 +105,15 @@ public ComponentFeatureImageResolver mediaHandlerProperty(@NotNull String key, @
return this;
}

/**
* @param value Image from page image
* @return self
*/
public ComponentFeatureImageResolver imageFromPageImage(boolean value) {
this.imageFromPageImage = value;
return this;
}

/**
* @param value Alt Value from DAM
* @return self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ void testInvalidAssetReference() {
void testWithAssetImage() {
context.currentResource(context.create().resource(page, "image",
PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE,
PN_IMAGE_FROM_PAGE_IMAGE, false,
PN_MEDIA_REF_STANDARD, asset.getPath(),
JCR_TITLE, "Resource Title",
PN_ALT, "Resource Alt"));
Expand Down Expand Up @@ -192,7 +193,6 @@ void testWithAssetImageFromPage() {

context.currentResource(context.create().resource(page1, "image",
PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE,
PN_IMAGE_FROM_PAGE_IMAGE, true,
JCR_TITLE, "Resource Title",
PN_ALT, "Resource Alt"));

Expand Down Expand Up @@ -221,6 +221,7 @@ void testWithAssetImageFromPage() {
void testWithUploadedImage() {
Resource imageResource = context.create().resource(page, "image",
PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE,
PN_IMAGE_FROM_PAGE_IMAGE, false,
NN_MEDIA_INLINE_STANDARD + "Name", "file1.png");
context.load().binaryFile("/files/test.png", imageResource.getPath() + "/" + NN_MEDIA_INLINE_STANDARD, ContentType.PNG);
context.currentResource(imageResource);
Expand Down Expand Up @@ -252,6 +253,7 @@ void testWithImageAndLink() {

context.currentResource(context.create().resource(page, "image",
PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE,
PN_IMAGE_FROM_PAGE_IMAGE, false,
PN_MEDIA_REF_STANDARD, asset.getPath(),
PN_LINK_TITLE, ExternalLinkType.ID,
PN_LINK_EXTERNAL_REF, "http://myhost"));
Expand Down Expand Up @@ -280,6 +282,7 @@ void testWithImageAndLink() {
void testWithImageAndLink_Decorative() {
context.currentResource(context.create().resource(page, "image",
PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE,
PN_IMAGE_FROM_PAGE_IMAGE, false,
PN_MEDIA_REF_STANDARD, asset.getPath(),
PN_LINK_TITLE, ExternalLinkType.ID,
PN_LINK_EXTERNAL_REF, "http://myhost",
Expand All @@ -304,6 +307,7 @@ void testWithImageAndLink_Decorative_ContentPolicy() {

context.currentResource(context.create().resource(page, "image",
PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE,
PN_IMAGE_FROM_PAGE_IMAGE, false,
PN_MEDIA_REF_STANDARD, asset.getPath(),
PN_LINK_TITLE, ExternalLinkType.ID,
PN_LINK_EXTERNAL_REF, "http://myhost"));
Expand All @@ -322,6 +326,7 @@ void testWithImageAndLink_Decorative_ContentPolicy() {
void testWithImage_TitleAltNotFormAsset() {
context.currentResource(context.create().resource(page, "image",
PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE,
PN_IMAGE_FROM_PAGE_IMAGE, false,
PN_MEDIA_REF_STANDARD, asset.getPath(),
JCR_TITLE, "Resource Title",
PN_ALT, "Resource Alt",
Expand All @@ -342,6 +347,7 @@ void testWithImage_TitleAltNotFormAsset_ContentPolicy() {

context.currentResource(context.create().resource(page, "image",
PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE,
PN_IMAGE_FROM_PAGE_IMAGE, false,
PN_MEDIA_REF_STANDARD, asset.getPath(),
JCR_TITLE, "Resource Title",
PN_ALT, "Resource Alt"));
Expand All @@ -358,6 +364,7 @@ void testWithNoImageAsset() {

context.currentResource(context.create().resource(page, "image",
PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE,
PN_IMAGE_FROM_PAGE_IMAGE, false,
PN_MEDIA_REF_STANDARD, pdfAsset.getPath()));

Image underTest = AdaptTo.notNull(context.request(), Image.class);
Expand All @@ -369,6 +376,7 @@ void testWithNoImageAsset() {
void testDisplayPopupTitle() {
context.currentResource(context.create().resource(page, "image",
PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE,
PN_IMAGE_FROM_PAGE_IMAGE, false,
PN_MEDIA_REF_STANDARD, asset.getPath(),
PN_DISPLAY_POPUP_TITLE, false));

Expand All @@ -384,6 +392,7 @@ void testDisplayPopupTitle_ContentPolicy() {

context.currentResource(context.create().resource(page, "image",
PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE,
PN_IMAGE_FROM_PAGE_IMAGE, false,
PN_MEDIA_REF_STANDARD, asset.getPath()));

Image underTest = AdaptTo.notNull(context.request(), Image.class);
Expand All @@ -398,6 +407,7 @@ void testLazyEnabled_ContentPolicy() {

context.currentResource(context.create().resource(page, "image",
PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE,
PN_IMAGE_FROM_PAGE_IMAGE, false,
PN_MEDIA_REF_STANDARD, asset.getPath()));

Image underTest = AdaptTo.notNull(context.request(), Image.class);
Expand All @@ -413,6 +423,7 @@ void testUUID() {

context.currentResource(context.create().resource(page, "image",
PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE,
PN_IMAGE_FROM_PAGE_IMAGE, false,
PN_MEDIA_REF_STANDARD, asset.getPath()));

Image underTest = AdaptTo.notNull(context.request(), Image.class);
Expand All @@ -431,6 +442,7 @@ void testUUID_Disabled() {

context.currentResource(context.create().resource(page, "image",
PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE,
PN_IMAGE_FROM_PAGE_IMAGE, false,
PN_MEDIA_REF_STANDARD, asset.getPath()));

Image underTest = AdaptTo.notNull(context.request(), Image.class);
Expand All @@ -448,6 +460,7 @@ void testWidths() {

context.currentResource(context.create().resource(page, "image",
PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE,
PN_IMAGE_FROM_PAGE_IMAGE, false,
PN_MEDIA_REF_STANDARD, asset.getPath()));

Image underTest = AdaptTo.notNull(context.request(), Image.class);
Expand All @@ -464,6 +477,7 @@ void testWidths() {
void testAreas() {
context.currentResource(context.create().resource(page, "image",
PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE,
PN_IMAGE_FROM_PAGE_IMAGE, false,
PN_MEDIA_REF_STANDARD, asset.getPath(),
PN_MAP, ImageAreaTestData.MAP_STRING));

Expand All @@ -480,6 +494,7 @@ void testWithImageAutoCropping_ContentPolicy() {

context.currentResource(context.create().resource(page, "image",
PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE,
PN_IMAGE_FROM_PAGE_IMAGE, false,
PN_MEDIA_REF_STANDARD, asset.getPath()));

Image underTest = AdaptTo.notNull(context.request(), Image.class);
Expand All @@ -501,6 +516,7 @@ void testWithImageAutoCropping_ContentPolicy_WrappedResource() {

Resource resource = context.create().resource(page, "image",
PROPERTY_RESOURCE_TYPE, DELEGATE_RESOURCE_TYPE,
PN_IMAGE_FROM_PAGE_IMAGE, false,
PN_MEDIA_REF_STANDARD, asset.getPath());

// set context resource to wrapped resource
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
jcr:primaryType="cq:Page">
<jcr:content
cq:tags="[core-components-examples:component-type/page-authoring]"
Expand Down Expand Up @@ -72,6 +72,7 @@
altValueFromDAM="true"
displayPopupTitle="true"
fileReference="/content/dam/core-components-examples/library/sample-assets/lava-into-ocean.jpg"
imageFromPageImage="false"
isDecorative="false"
titleValueFromDAM="true"/>
</component>
Expand Down Expand Up @@ -118,6 +119,7 @@
altValueFromDAM="true"
displayPopupTitle="false"
fileReference="/content/dam/core-components-examples/library/sample-assets/lava-into-ocean.jpg"
imageFromPageImage="false"
isDecorative="false"
titleValueFromDAM="true"/>
</component>
Expand Down Expand Up @@ -164,6 +166,7 @@
altValueFromDAM="true"
displayPopupTitle="true"
fileReference="/content/dam/core-components-examples/library/sample-assets/snowy-mountain-glacier.jpg"
imageFromPageImage="false"
isDecorative="false"
linkURL="/content/wcmio-core-components-examples/library/core-content/image"
titleValueFromDAM="true"/>
Expand Down Expand Up @@ -211,6 +214,7 @@
altValueFromDAM="true"
displayPopupTitle="true"
fileReference="/content/dam/core-components-examples/library/components/component.svg"
imageFromPageImage="false"
isDecorative="false"
titleValueFromDAM="true"/>
</component>
Expand All @@ -234,6 +238,47 @@
reference="../../component"/>
</info>
</demo>
<title_290385105
cq:styleIds="[1544759676459]"
jcr:primaryType="nt:unstructured"
jcr:title="Empty Image"
sling:resourceType="wcm-io/wcm/core/components/title/v2/title"
type="h3"/>
<text_1337505106
jcr:primaryType="nt:unstructured"
sling:resourceType="wcm-io/wcm/core/components/text/v2/text"
text="&lt;p>An empty image component renders the featured image defined for the page.&lt;/p>"
textIsRich="true"/>
<demo_1473529394
jcr:primaryType="nt:unstructured"
sling:resourceType="core-components-examples/components/demo">
<component
jcr:primaryType="nt:unstructured"
sling:resourceType="core-components-examples/components/demo/component">
<image
jcr:primaryType="nt:unstructured"
sling:resourceType="wcm-io/wcm/core/components/image/v3/image"/>
</component>
<info
jcr:primaryType="nt:unstructured"
sling:resourceType="core-components-examples/components/tabs">
<properties
cq:panelTitle="Properties"
jcr:primaryType="nt:unstructured"
sling:resourceType="core-components-examples/components/demo/properties"
reference="../../component"/>
<markup
cq:panelTitle="Markup"
jcr:primaryType="nt:unstructured"
sling:resourceType="core-components-examples/components/demo/markup"
reference="../../component"/>
<json
cq:panelTitle="JSON"
jcr:primaryType="nt:unstructured"
sling:resourceType="core-components-examples/components/demo/json"
reference="../../component"/>
</info>
</demo_1473529394>
</responsivegrid>
</root>
<cq:featuredimage
Expand Down

0 comments on commit 2a032e9

Please sign in to comment.