Skip to content

Commit f5bdc05

Browse files
authored
Fixing sling output mappings in aemform embed component (#1530)
* Fixing sling output mappings in aemform embed component * Fixing sling output mappings in aemform embed component
1 parent be68afd commit f5bdc05

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

bundles/core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v1/aemform/AEMFormImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,12 @@ public boolean isFormSelected() {
279279

280280
@Override
281281
public String getThankyouPage() {
282+
if (request != null && StringUtils.isNotBlank(thankyouPage)) {
283+
ResourceResolver resourceResolver = request.getResourceResolver();
284+
if (resourceResolver != null) {
285+
thankyouPage = StringUtils.replace(resourceResolver.map(thankyouPage), "_jcr_content", "jcr:content");
286+
}
287+
}
282288
return GuideUtils.getRedirectUrl(thankyouPage, null);
283289
}
284290

bundles/core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/aemform/AEMFormImplTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ class AEMFormImplTest {
4141
private static final String GRID_LANG = ROOT_PAGE_LANG + "/jcr:content/root/responsivegrid";
4242
private static final String FORM_1 = "/aemform-1";
4343
private static final String FORM_2 = "/aemform-2";
44+
private static final String FORM_WITH_SLINGMAPPINGS = "/aemformv2_slingmappings";
4445
private static final String PATH_FORM_1 = GRID + FORM_1;
4546
private static final String PATH_FORM_2 = GRID + FORM_2;
47+
private static final String PATH_FORM_SLINGMAPPINGS = GRID + FORM_WITH_SLINGMAPPINGS;
4648
private static final String PATH_FORM_LANG = GRID_LANG + FORM_1;
4749

4850
private final AemContext context = FormsCoreComponentTestContext.newAemContext();
@@ -294,6 +296,16 @@ void testJSONExport() throws Exception {
294296
Utils.testJSONExport(aemform, Utils.getTestExporterJSONPath(BASE, PATH_FORM_1));
295297
}
296298

299+
@Test
300+
void testGetThankYouPageWithResourceResolver() {
301+
// Get form under test using test resource that has _jcr_content in thankyou page path
302+
AEMForm aemForm = getAEMFormUnderTest(PATH_FORM_SLINGMAPPINGS);
303+
304+
// Test the method - verify _jcr_content replacement
305+
String result = aemForm.getThankyouPage();
306+
assertEquals("/content/jcr:content/thank/page.html", result);
307+
}
308+
297309
private AEMForm getAEMFormUnderTest(String resourcePath) {
298310
context.currentResource(resourcePath);
299311
MockSlingHttpServletRequest request = context.request();

bundles/core/src/test/resources/aemform/test-content.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@
8080
"useiframe" : "true",
8181
"usePageLocale" : "true",
8282
"enableFocusOnFirstField" : true
83+
},
84+
"aemformv2_slingmappings" : {
85+
"jcr:primaryType": "nt:unstructured",
86+
"jcr:title": "",
87+
"sling:resourceType": "core/fd/components/aemform/v1/aemform",
88+
"thankyouPage": "/content/_jcr_content/thank/page"
8389
}
8490
}
8591
}

0 commit comments

Comments
 (0)