Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
vladbailescu authored Feb 20, 2025
2 parents dbf0306 + d8834a1 commit a414fb3
Show file tree
Hide file tree
Showing 28 changed files with 480 additions and 24 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ For existing projects, take example from the [AEM Project Archetype](https://git

### System Requirements

Core Components | AEM as a Cloud Service | AEM 6.5 | Java SE | Maven
----------------|------------------------|-----------|---------|---------
[2.27.0+](https://github.com/adobe/aem-core-wcm-components/releases/tag/core.wcm.components.reactor-2.23.4) | Continual | 6.5.21.0+ | 8, <br/>11 | 3.3.9+
Core Components | AEM as a Cloud Service | AEM 6.5 | Java SE | Maven
----------------|------------------------|--------------|-----------|---------
[>= 2.26.x](https://github.com/adobe/aem-core-wcm-components/releases/tag/core.wcm.components.reactor-2.23.4) | Continual | \>= 6.5.21.0 | 11 | \>= 3.3.9
[<= 2.25.x](https://github.com/adobe/aem-core-wcm-components/releases/tag/core.wcm.components.reactor-2.23.4) | Not applicable | \<= 6.5.21.0 | 8 <br/>11 | \<= 3.3.9


For the requirements from previous Core Component releases, see [Historical System Requirements](VERSIONS.md).

Expand Down
4 changes: 2 additions & 2 deletions VERSIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ See below for a full list of system requirements for historical versions of the

Core Components | Extension | AEM 6.5 | AEM 6.4 | AEM 6.3 | Java | Maven
----------------|-----------|-----------|---------|---------|-------|------
[2.27.0](https://github.com/adobe/aem-core-wcm-components/releases/tag/core.wcm.components.reactor-2.26.0) | - | 6.5.21.0+ | - | - | 8, 11 | 3.3.9+
[2.26.0](https://github.com/adobe/aem-core-wcm-components/releases/tag/core.wcm.components.reactor-2.26.0) | - | 6.5.21.0+ | - | - | 8, 11 | 3.3.9+
[2.27.0](https://github.com/adobe/aem-core-wcm-components/releases/tag/core.wcm.components.reactor-2.26.0) | - | 6.5.21.0+ | - | - | 11 | 3.3.9+
[2.26.0](https://github.com/adobe/aem-core-wcm-components/releases/tag/core.wcm.components.reactor-2.26.0) | - | 6.5.21.0+ | - | - | 11 | 3.3.9+
[2.25.4](https://github.com/adobe/aem-core-wcm-components/releases/tag/core.wcm.components.reactor-2.25.4) | - | 6.5.21.0+ | - | - | 8, 11 | 3.3.9+
[2.25.2](https://github.com/adobe/aem-core-wcm-components/releases/tag/core.wcm.components.reactor-2.25.2) | - | 6.5.21.0+ | - | - | 8, 11 | 3.3.9+
[2.25.0](https://github.com/adobe/aem-core-wcm-components/releases/tag/core.wcm.components.reactor-2.25.0) | - | 6.5.21.0+ | - | - | 8, 11 | 3.3.9+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@

import javax.annotation.PostConstruct;

import com.day.cq.wcm.api.designer.Style;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Default;
import org.apache.sling.models.annotations.Exporter;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.OSGiService;
import org.apache.sling.models.annotations.injectorspecific.ScriptVariable;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;
import org.apache.sling.models.annotations.injectorspecific.*;

import com.adobe.cq.export.json.ComponentExporter;
import com.adobe.cq.export.json.ExporterConstants;
import com.adobe.cq.wcm.core.components.internal.form.FormConstants;
import com.adobe.cq.wcm.core.components.models.form.Text;
import com.day.cq.wcm.foundation.forms.FormStructureHelperFactory;
import com.day.cq.wcm.foundation.forms.FormsHelper;
import org.jetbrains.annotations.Nullable;

@Model(adaptables = SlingHttpServletRequest.class,
adapters = {Text.class, ComponentExporter.class},
Expand All @@ -54,6 +54,8 @@ public class TextImpl extends AbstractFieldImpl implements Text, ComponentExport
private static final boolean PROP_USE_PLACEHOLDER_DEFAULT = false;
private static final int PROP_ROWS_DEFAULT = 2;
private static final boolean PROP_HIDE_TITLE_DEFAULT = false;
public static final String PROP_DISPLAY_VALIDATION = "displayValidation";
public static final boolean PROP_DISPLAY_VALIDATION_DEFAULT = false;

@Self
private SlingHttpServletRequest slingRequest;
Expand Down Expand Up @@ -103,6 +105,16 @@ public class TextImpl extends AbstractFieldImpl implements Text, ComponentExport
@Default(booleanValues = PROP_HIDE_TITLE_DEFAULT)
private boolean hideTitle;

/**
* The current style for this component.
*/
@ScriptVariable(injectionStrategy = InjectionStrategy.OPTIONAL)
@JsonIgnore
@Nullable
protected Style currentStyle;

private boolean displayValidationMassages;

@PostConstruct
private void initModel() {
slingRequest.setAttribute(FormsHelper.REQ_ATTR_FORM_STRUCTURE_HELPER,
Expand All @@ -114,6 +126,10 @@ private void initModel() {
if (usePlaceholder) {
placeholder = helpMessage;
}

if (currentStyle !=null) {
displayValidationMassages = currentStyle.get(PROP_DISPLAY_VALIDATION, PROP_DISPLAY_VALIDATION_DEFAULT);
}
}

@Override
Expand Down Expand Up @@ -190,4 +206,8 @@ public boolean hideTitle() {
return hideTitle;
}

@Override
public boolean displayValidation() {
return displayValidationMassages;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ private void initNextGenerationDynamicMedia() {
properties = resource.getValueMap();
String fileReference = properties.get("fileReference", String.class);
String smartCrop = properties.get("smartCropRendition", String.class);
String modifiers = properties.get("imageModifiers", String.class);
if (isNgdmImageReference(fileReference)) {
int width = currentStyle.get(PN_DESIGN_RESIZE_WIDTH, DEFAULT_NGDM_ASSET_WIDTH);
NextGenDMImageURIBuilder builder = new NextGenDMImageURIBuilder(nextGenDynamicMediaConfig, fileReference)
Expand All @@ -339,6 +340,9 @@ private void initNextGenerationDynamicMedia() {
if(StringUtils.isNotEmpty(smartCrop) && !StringUtils.equals(smartCrop, SMART_CROP_AUTO)) {
builder.withSmartCrop(smartCrop);
}
if (StringUtils.isNotEmpty(modifiers)) {
builder.withImageModifiers(modifiers);
}
src = builder.build();
ngdmImage = true;
hasContent = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class NextGenDMImageURIBuilder {
private int height;
private boolean preferWebp = true;

private String modifiers;

public NextGenDMImageURIBuilder(NextGenDynamicMediaConfig config, String fileReference) {
this.config = config;
this.fileReference = fileReference;
Expand Down Expand Up @@ -84,6 +86,15 @@ public NextGenDMImageURIBuilder withPreferWebp(boolean preferWebp) {
return this;
}

/**
* Set extra image modifiers.
* @param modifiersStr
*/
public NextGenDMImageURIBuilder withImageModifiers(String modifiersStr) {
this.modifiers = modifiersStr;
return this;
}

/**
* Use this to create a NextGen Dynamic Media Image URI.
* @return a uri.
Expand Down Expand Up @@ -124,6 +135,13 @@ public String build() {
}
uriBuilder.deleteCharAt(uriBuilder.length() - 1);
}
if(StringUtils.isNotEmpty(this.modifiers)) {
if (this.modifiers.startsWith("&")) {
uriBuilder.append(this.modifiers);
} else {
uriBuilder.append("&" + this.modifiers);
}
}
return uriBuilder.toString();
}
LOGGER.info("Invalid fileReference or NGDMConfig. fileReference = {}", this.fileReference);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ protected void activate(Configuration configuration) {
@Override
protected void doPost(@NotNull SlingHttpServletRequest request, @NotNull final SlingHttpServletResponse response)
throws ServletException, IOException {
// response will have content type text/html since it is represented by a JSP without another content type set
// JSPs have this content type by default
// So set this content type in advance inside response, in order to avoid breaking request dispatcher contract
// More info https://jakarta.ee/specifications/servlet/4.0/apidocs/javax/servlet/requestdispatcher#include-javax.servlet.ServletRequest-javax.servlet.ServletResponse-
response.setContentType("text/html");
formsHandlingServletHelper.doPost(request, response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public interface Text extends Field {

/**
* Checks if the this text field is mandatory.
* Checks if the text field is mandatory.
*
* @return {@code true} if the field must have a input, {@code false} otherwise
* @since com.adobe.cq.wcm.core.components.models.form 13.0.0; marked <code>default</code> in 14.1.0
Expand Down Expand Up @@ -107,4 +107,14 @@ default int getRows() {
default boolean hideTitle() {
return false;
}

/**
* Checks if the validation messages should be displayed.
*
* @return {@code true} if the validation messages should be displayed, {@code false} otherwise
* @since com.adobe.cq.wcm.core.components.models.form 14.5.0
*/
default boolean displayValidation() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* version, is bound to this proxy component resource type.
* </p>
*/
@Version("14.4.0")
@Version("14.5.0")
package com.adobe.cq.wcm.core.components.models.form;

import org.osgi.annotation.versioning.Version;
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class TextImplTest {
private static final String TEXTINPUT1_PATH = CONTAINING_PAGE + "/jcr:content/root/responsivegrid/container/text";
private static final String TEXTINPUT2_PATH = CONTAINING_PAGE + "/jcr:content/root/responsivegrid/container/text_185087333";
private static final String TEXTINPUT3_PATH = CONTAINING_PAGE + "/jcr:content/root/responsivegrid/container/text-v2";
private static final String TEXTINPUT4_PATH = CONTAINING_PAGE + "/jcr:content/root/responsivegrid/container/text-v2-2";
private static final String TEXTINPUT5_PATH = CONTAINING_PAGE + "/jcr:content/root/responsivegrid/container/text-v2-3";


public final AemContext context = CoreComponentTestContext.newAemContext();
Expand Down Expand Up @@ -79,6 +81,7 @@ public void testInputWithCustomDataAndAttributes() {
assertEquals(3, text.getRows());
assertEquals("Custom help/placeholder message", text.getHelpMessage());
assertTrue(text.hideTitle());
assertFalse(text.displayValidation());
Utils.testJSONExport(text, Utils.getTestExporterJSONPath(TEST_BASE, TEXTINPUT2_PATH));
}

Expand All @@ -88,6 +91,24 @@ public void testV2JSONExport() {
Utils.testJSONExport(text, Utils.getTestExporterJSONPath(TEST_BASE, TEXTINPUT3_PATH));
}

@Test
public void testInputWithPolicyDisplayValidationFalse() {
context.contentPolicyMapping("core/wcm/components/form/text/v2/text", "displayValidation", false);
Text text = getTextUnderTest(TEXTINPUT4_PATH);
assertEquals("Custom Name", text.getName());
assertEquals("Custom title", text.getTitle());
assertFalse(text.displayValidation());
}

@Test
public void testInputWithPolicyDisplayValidationTrue() {
context.contentPolicyMapping("core/wcm/components/form/text/v2/text", "displayValidation", true);
Text text = getTextUnderTest(TEXTINPUT5_PATH);
assertEquals("Custom Name", text.getName());
assertEquals("Custom title", text.getTitle());
assertTrue(text.displayValidation());
}

private Text getTextUnderTest(String resourcePath) {
context.currentResource(Objects.requireNonNull(context.resourceResolver().getResource(resourcePath)));
return context.request().adaptTo(Text.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class ImageImplTest extends com.adobe.cq.wcm.core.components.internal.models.v2.
private static final String PAGE3_IMAGE0_PATH = PAGE3 + "/jcr:content/root/page3_image0";
private static final String NGDM_IMAGE1_PATH = "/content/ngdm_test_page/jcr:content/root/ngdm_test_page_image1";
private static final String NGDM_SMARTCROP_IMAGE_PATH = "/content/ngdm_test_page/jcr:content/root/ngdm_test_page_smartcrop_image";

private static final String NGDM_MODIFIERS_IMAGE_PATH = "/content/ngdm_test_page/jcr:content/root/ngdm_test_page_modifiers_image";
private static final String NGDM_SMARTCROP_AUTO_IMAGE_PATH = "/content/ngdm_test_page/jcr:content/root/ngdm_test_page_smartcrop_image_auto";


Expand Down Expand Up @@ -731,6 +733,19 @@ void testNgdmImageWithSmartCropRendition() {
Utils.testJSONExport(image, Utils.getTestExporterJSONPath(testBase, NGDM_SMARTCROP_IMAGE_PATH));
}

@Test
void testNgdmImageWithModifiers() {
MockNextGenDynamicMediaConfig config = new MockNextGenDynamicMediaConfig();
config.setEnabled(true);
config.setRepositoryId("testrepo");
config.setAssetMetadataPath("/adobe/assets/{asset-id}/metadata");
context.registerInjectActivateService(config);

Image image = getImageUnderTest(NGDM_MODIFIERS_IMAGE_PATH);
Utils.testJSONExport(image, Utils.getTestExporterJSONPath(testBase, NGDM_MODIFIERS_IMAGE_PATH));
assertTrue(image.getSrc().contains("&width=100&height=200"));
}

@Test
void testNgdmImageWithAutoSmartCropRendition() throws Exception {
String expectedMetadataAPIResponseJSON = "{\"assetId\":\"urn:aaid:aem:33b6255d-a978-43ad-8e2e-ef5677c64715\",\"repositoryMetadata\":{\"smartcrops\":{\"Large\":{\"height\":\"1200\",\"left\":\"0.0\",\"manualCrop\":\"false\",\"width\":\"800\",\"top\":\"0.16\"},\"Medium\":{\"height\":\"800\",\"left\":\"0.0\",\"manualCrop\":\"false\",\"width\":\"600\",\"top\":\"0.0\"}}}}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@
},
"1538637399370": {
"jcr:primaryType": "nt:unstructured",
"valueFormat": "YYYY-MM-DD[T]HH:mm:ss.000Z",
"emptyText": "YYYY-MM-DD HH:mm",
"valueFormat": "yyyy-MM-dd[T]HH:mm:ss.000Z",
"emptyText": "yyyy-MM-dd HH:mm",
"listOrder": "5",
"valueType": "calendar",
"displayedFormat": "YYYY-MM-DD HH:mm",
"displayedFormat": "yyyy-MM-dd HH:mm",
"showEmptyInReadOnly": "true",
"metaType": "date",
"name": "dateAndTimeField",
Expand Down
38 changes: 37 additions & 1 deletion bundles/core/src/test/resources/form/text/test-content.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,43 @@
"usePlaceholder": "true",
"rows": 3,
"hideTitle": true
}
},
"text-v2-2": {
"jcr:primaryType": "nt:unstructured",
"jcr:title": "Custom title",
"constraintMessage": "The value should be a valid email address",
"showHideExpression": "((givenName.equals(\"\"Referees\"\")))",
"readOnly": true,
"helpMessage": "Custom help/placeholder message",
"required": true,
"name": "Custom Name",
"type": "email",
"useTextarea": true,
"value": "Prefilled Sample Input",
"sling:resourceType": "core/wcm/components/form/text/v2/text",
"requiredMessage": "please fill the field",
"usePlaceholder": "true",
"rows": 3,
"hideTitle": true
},
"text-v2-3": {
"jcr:primaryType": "nt:unstructured",
"jcr:title": "Custom title",
"constraintMessage": "The value should be a valid email address",
"showHideExpression": "((givenName.equals(\"\"Referees\"\")))",
"readOnly": true,
"helpMessage": "Custom help/placeholder message",
"required": true,
"name": "Custom Name",
"type": "email",
"useTextarea": true,
"value": "Prefilled Sample Input",
"sling:resourceType": "core/wcm/components/form/text/v2/text",
"requiredMessage": "please fill the field",
"usePlaceholder": "true",
"rows": 3,
"hideTitle": true
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"id": "image-06acc3dd21",
"src": "https://testrepo/adobe/dynamicmedia/deliver/urn:aaid:aem:e82c3c87-1453-48f5-844b-1822fb610911/cutfruits.png?width=640&preferwebp=true&width=100&height=200",
"lazyEnabled": true,
"sizes": "",
"dataLayer": {
"image-06acc3dd21": {
"@type": "core/wcm/components/image/v3/image"
}
},
":type": "core/wcm/components/image/v3/image"
}
7 changes: 7 additions & 0 deletions bundles/core/src/test/resources/image/v3/test-content.json
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,13 @@
"fileReference": "/urn:aaid:aem:e82c3c87-1453-48f5-844b-1822fb610911/cutfruits.png",
"smartCropRendition": "Medium"
},
"ngdm_test_page_modifiers_image": {
"jcr:primaryType": "nt:unstructured",
"jcr:createdBy": "admin",
"sling:resourceType": "core/wcm/components/image/v3/image",
"fileReference": "/urn:aaid:aem:e82c3c87-1453-48f5-844b-1822fb610911/cutfruits.png",
"imageModifiers": "&width=100&height=200"
},
"ngdm_test_page_smartcrop_image_auto": {
"jcr:primaryType": "nt:unstructured",
"jcr:createdBy": "admin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
<template data-sly-template.element="${@ date='The date', format='The format'}">
<!--/* set a default format if none was provided */-->
<sly data-sly-test.format="${format ? format : 'YYYY-MM-dd HH:mm'}"></sly>
<sly data-sly-test.format="${format ? format : 'yyyy-MM-dd HH:mm'}"></sly>
<!--/* i18n will allow to customise format based on locale as it's applied to the formatting string before the actual date formatting is done */-->
${format @ format=date, type='date', i18n}
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ Text form field component written in HTL.
### Use Object
The Form Text component uses the `com.adobe.cq.wcm.core.components.models.form.Text` Sling Model for its Use-object.

### Component Policy Configuration Properties
The following configuration properties are used:

1. `./displayValidation` - defines whether the text field should display a label for the validation messages.

### Edit Dialog Properties
The following properties are written to JCR for this Form Text component and are expected to be available as `Resource` properties:

Expand Down Expand Up @@ -63,6 +68,7 @@ BLOCK cmp-form-text
ELEMENT cmp-form-text__help-block
ELEMENT cmp-form-text__textarea
ELEMENT cmp-form-text__text
ELEMENT cmp-form-text__validation-message
```

## JavaScript Data Attribute Bindings
Expand Down
Loading

0 comments on commit a414fb3

Please sign in to comment.