Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed forms in different sites - DO NOT DELETE - DO NOT MERGE #1473

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions it/apps/src/main/content/META-INF/vault/filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<workspaceFilter version="1.0">
<filter root="/apps/forms-core-components-it"/>
<filter root="/apps/wknd"/>
<filter root="/apps/forms-core-components-it/config"/>
<filter root="/apps/core/fd/af-clientlibs/core-forms-components-runtime-all/resources/i18n" mode="update"/>
</workspaceFilter>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:Folder"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="nt:unstructured"
contentTypes="[text/html]"
enabled="{Boolean}true"
generatorType="htmlparser"
order="1"
paths="[/content]"
serializerType="htmlwriter"
transformerTypes="[custom-linkrewriter]">
<generator-htmlparser
jcr:primaryType="nt:unstructured"
includeTags="[LINK,SCRIPT]" />
</jcr:root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:Component"
jcr:title="Forms Embed Component"
componentGroup=".Sites - Content"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## This component should be deployed in the Sites' instance where we need to embed the form
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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:primaryType="nt:unstructured"
jcr:title="Properties"
sling:resourceType="cq/gui/components/authoring/dialog">
<content
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns">
<items jcr:primaryType="nt:unstructured">
<column
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container">
<items jcr:primaryType="nt:unstructured">
<text
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
fieldLabel="Forms URL - should be prefixed with custom"
name="./formsUrl"/>
</items>
</column>
</items>
</content>
</jcr:root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<div>
<!--TODO Replace the package name of the Model -->
<div class="cmp-formsembed__item" data-sly-use.model="com.adobe.cq.forms.core.components.it.models.embed.FormsEmbed">
<div class="cmp-formsembed-widget" data-forms-url=${model.formsUrl}>

<div class="afsection">
<div data-sly-test="${wcmmode.edit}">
Your Form Will Appear Here
</div>
</div>
</div>
</div>
<div data-sly-test="${!wcmmode.edit}">
<script>
var updateElementContent = function (targetElement, newHtml) {
targetElement.innerHTML = newHtml;
Array.from(targetElement.querySelectorAll("script")).forEach(oldScriptElement => {
const newScriptElement = document.createElement("script");
Array.from(oldScriptElement.attributes).forEach(attribute => {
newScriptElement.setAttribute(attribute.name, attribute.value);
});
const scriptText = document.createTextNode(oldScriptElement.innerHTML);
newScriptElement.appendChild(scriptText);
oldScriptElement.parentNode.replaceChild(newScriptElement, oldScriptElement);
});
}
var formsUrl = document.querySelector('.cmp-formsembed-widget').getAttribute('data-forms-url');
var options = {path:formsUrl, CSS_Selector:".afsection"};
if (options.path) {
fetch(options.path, {
method: 'GET',
// You can include additional headers or data here if needed
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.text();
})
.then(data => {
var element = document.querySelector(options.CSS_Selector);
if (element) {
updateElementContent(element, data);
}
})
.catch(error => {
// Error handling
console.error('Error fetching data:', error);
});
} else {
if (typeof console !== "undefined") {
console.log("Path of Adaptive Form not specified to loadAdaptiveForm");
}
}
</script>
</div>
</div>
2 changes: 1 addition & 1 deletion it/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ Import-Package: javax.annotation;version=0.0.0,*
<dependency>
<groupId>com.adobe.aem</groupId>
<artifactId>core-forms-components-af-core</artifactId>
<version>3.0.70</version>
<version>${project.version}</version>
</dependency>
<!-- Json web token dependencies for oauth2 flow -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.adobe.cq.forms.core.components.it.models.embed;

import com.adobe.cq.wcm.core.components.models.Component;
import org.osgi.annotation.versioning.ConsumerType;

@ConsumerType
public interface FormsEmbed extends Component {

String getFormsUrl();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.adobe.cq.forms.core.components.it.models.embed;

import com.adobe.cq.export.json.ComponentExporter;
import com.adobe.cq.export.json.ExporterConstants;
import com.drew.lang.annotations.Nullable;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.annotations.Exporter;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;

@Model(
adaptables = SlingHttpServletRequest.class,
adapters = {FormsEmbed.class, ComponentExporter.class},
resourceType = FormsEmbedImpl.RESOURCE_TYPE
)
@Exporter(
name = ExporterConstants.SLING_MODEL_EXPORTER_NAME,
extensions = ExporterConstants.SLING_MODEL_EXTENSION
)
public class FormsEmbedImpl implements FormsEmbed {

// TODO replace app name
public static final String RESOURCE_TYPE = "forms-core-component-it/components/formsembed";

@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
@Nullable
protected String formsUrl;


@Override
public String getFormsUrl() {
return formsUrl;
}
}
Loading