Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.adobe.cq.forms.core.components.models.form.ThankYouOption;
import com.adobe.cq.forms.core.components.util.AbstractContainerImpl;
import com.adobe.cq.forms.core.components.util.ComponentUtils;
import com.day.cq.commons.LanguageUtil;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;
import com.fasterxml.jackson.annotation.JsonIgnore;
Expand Down Expand Up @@ -269,6 +270,26 @@ public String getLang() {
}
}

@Override
public String getContainingPageLang() {
// todo: right now it is copy of aem form because app is part of far, and af-apps is not pare of far
if (request != null) {
Page currentPage = getCurrentPage();
if (!GuideWCMUtils.isForms(currentPage.getPath())) {
String pagePath = currentPage.getPath(), pageLocaleRoot = LanguageUtil.getLanguageRoot(pagePath), locale = "";
if (StringUtils.isNotBlank(pageLocaleRoot)) {
int localeStartIndex = StringUtils.lastIndexOf(pageLocaleRoot, '/');
locale = StringUtils.substring(pageLocaleRoot, localeStartIndex + 1);
}
return locale;
} else {
return FormContainer.super.getContainingPageLang();
}
} else {
return FormContainer.super.getContainingPageLang();
}
}

@Override
public @NotNull Map<String, Object> getProperties() {
Map<String, Object> properties = super.getProperties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,17 @@ default String getLang() {
return "en-US";
}

/**
* Returns the language of the containing page
*
* @return the language of the containing page
* @since com.adobe.cq.forms.core.components.models.form 4.7.1
*/
@JsonIgnore
default String getContainingPageLang() {
return getLang();
}

/**
* Returns the redirect url after form submission
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
* version, is bound to this proxy component resource type.
* </p>
*/
@Version("5.2.0")

@Version("5.2.1")
package com.adobe.cq.forms.core.components.models.form;

import org.osgi.annotation.versioning.Version;
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ public class FormContainerImplTest {
private static final String LIB_FORM_CONTAINER = "/libs/core/fd/components/form/container/v2/container";

protected static final String SITES_PATH = "/content/exampleSite";
protected static final String SITES_LANG_PATH = "/content/th/exampleSite";
protected static final String FORM_CONTAINER_PATH_IN_SITES = SITES_PATH + "/jcr:content/root/sitecontainer/formcontainer";
protected static final String FORM_CONTAINER_PATH_WITH_LANGUAGE_IN_SITES = SITES_LANG_PATH
+ "/jcr:content/root/sitecontainer/formcontainer";

protected static final String AF_PATH = "/content/forms/af/testAf";

Expand All @@ -83,7 +86,8 @@ void setUp() {
// resource up to find page
context.load().json(BASE + "/test-lib-form-container.json", LIB_FORM_CONTAINER); // required since v2 container resource type should
// be v1 for localization to work
context.load().json(BASE + "/test-forms-in-sites.json", "/content/exampleSite");
context.load().json(BASE + "/test-forms-in-sites.json", SITES_PATH);
context.load().json(BASE + "/test-forms-in-sites.json", SITES_LANG_PATH);
context.load().json(BASE + "/test-content.json", CONTENT_FORM_WITHOUT_PREFILL_ROOT);

context.registerService(SlingModelFilter.class, new SlingModelFilter() {
Expand Down Expand Up @@ -134,6 +138,13 @@ void testGetIdForSitePage() throws Exception {
assertEquals("L2NvbnRlbnQvZXhhbXBsZVNpdGUvamNyOmNvbnRlbnQvcm9vdC9zaXRlY29udGFpbmVyL2Zvcm1jb250YWluZXI=", formContainer.getId());
}

@Test
void testGetPageLangForSitePage() throws Exception {
FormContainer formContainer = Utils.getComponentUnderTest(FORM_CONTAINER_PATH_WITH_LANGUAGE_IN_SITES, FormContainer.class, context);
assertNotNull(formContainer.getContainingPageLang());
assertEquals("th", formContainer.getContainingPageLang());
}

@Test
void testGetAction() throws Exception {
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_1, FormContainer.class, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public Map<String, Object> submit(FormSubmitInfo formSubmitInfo) {
result.put("fd:redirectParameters", redirectParamMap);
} catch (Exception ex) {
logger.error("Error while using the AF Submit service", ex);

// todo: have to fix this
result.put(GuideConstants.FORM_SUBMISSION_ERROR, Boolean.TRUE);
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
id="${container.id}"
data-cmp-is="adaptiveFormContainer"
data-cmp-context-path="${request.contextPath}"
data-cmp-page-lang="${container.containingPageLang}"
data-cmp-path="${resource.path}"
class="cmp-adaptiveform-container cmp-container">

Expand Down
7 changes: 6 additions & 1 deletion ui.frontend/src/HTTPAPILayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ class HTTPAPILayer {
/**
* Retrieves the form definition for the specified form container path using the json exporter API
* @param {string} formContainerPath - The path of the form container.
* @param {string} pageLang - Language of the containing sites page
* @returns {Promise<Object>} - A Promise that resolves to the form definition.
*/
static async getFormDefinition(formContainerPath) {
static async getFormDefinition(formContainerPath, pageLang) {
const urlSearchParams = new URLSearchParams(window.location.search);
const params = Object.fromEntries(urlSearchParams.entries());
let lang = null;
Expand All @@ -64,6 +65,10 @@ class HTTPAPILayer {
lang = `${parts[parts.length - 2]}`;
}
}
// If 'afAcceptLang' is not set and URL selector is not present, use sites page language
if (lang === null && pageLang != null) {
lang = pageLang;
}
return await this.getJson(`${formContainerPath}.model.${lang !== null ? `${lang}.` : ""}json`);
}

Expand Down
3 changes: 2 additions & 1 deletion ui.frontend/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,14 @@ class Utils {
for (let i = 0; i < elements.length; i++) {
const dataset = Utils.readData(elements[i], formContainerClass);
const _path = dataset["path"];
const _pageLang = dataset["pageLang"];
if ('contextPath' in dataset) {
Utils.setContextPath(dataset['contextPath']);
}
if (_path == null) {
console.error(`data-${Constants.NS}-${formContainerClass}-path attribute is not present in the HTML element. Form cannot be initialized` )
} else {
const _formJson = await HTTPAPILayer.getFormDefinition(_path);
const _formJson = await HTTPAPILayer.getFormDefinition(_path, _pageLang);
console.debug("fetched model json", _formJson);
await this.registerCustomFunctions(_formJson.id);
const urlSearchParams = new URLSearchParams(window.location.search);
Expand Down