-
Notifications
You must be signed in to change notification settings - Fork 62
Embed forms in different sites - DO NOT DELETE - DO NOT MERGE #1473
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
Open
barshat7
wants to merge
7
commits into
dev
Choose a base branch
from
embed-forms-in-different-sites
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4d3b845
support to embed forms in different sites
barshat7 c413a1a
Merge branch 'dev' into embed-forms-in-different-sites
barshat7 3e18571
custom form container model for prefix path for prefill, custom funct…
barshat7 9bb509c
support to embed forms in different sites
barshat7 f846958
custom form container model for prefix path for prefill, custom funct…
barshat7 ac78189
osgi config for rewriter
barshat7 2b78cb0
Merge branch 'embed-forms-in-different-sites' of https://github.com/a…
barshat7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
it/apps/src/main/content/jcr_root/apps/forms-core-components-it/config/rewriter/.content.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"/> |
14 changes: 14 additions & 0 deletions
14
...t/jcr_root/apps/forms-core-components-it/config/rewriter/custom-linkrewriter/.content.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
5 changes: 5 additions & 0 deletions
5
...pps/src/main/content/jcr_root/apps/forms-core-components-it/sites/formsembed/.content.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"/> |
1 change: 1 addition & 0 deletions
1
.../main/content/jcr_root/apps/forms-core-components-it/sites/formsembed/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
23 changes: 23 additions & 0 deletions
23
...n/content/jcr_root/apps/forms-core-components-it/sites/formsembed/_cq_dialog/.content.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 abbviecloud" | ||
| name="./formsUrl"/> | ||
| </items> | ||
| </column> | ||
| </items> | ||
| </content> | ||
| </jcr:root> |
57 changes: 57 additions & 0 deletions
57
.../src/main/content/jcr_root/apps/forms-core-components-it/sites/formsembed/formsembed.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
10 changes: 10 additions & 0 deletions
10
it/core/src/main/java/com/adobe/cq/forms/core/components/it/models/embed/FormsEmbed.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } |
35 changes: 35 additions & 0 deletions
35
it/core/src/main/java/com/adobe/cq/forms/core/components/it/models/embed/FormsEmbedImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
99 changes: 99 additions & 0 deletions
99
...om/adobe/cq/forms/core/components/it/service/rewriter/CustomCloudRewriterTransformer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package com.adobe.cq.forms.core.components.it.service.rewriter; | ||
|
|
||
| import org.apache.sling.rewriter.DefaultTransformer; | ||
| import org.apache.sling.rewriter.TransformerFactory; | ||
| import org.osgi.service.component.annotations.Component; | ||
| import org.osgi.service.component.annotations.Reference; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.xml.sax.Attributes; | ||
| import org.xml.sax.SAXException; | ||
| import org.xml.sax.helpers.AttributesImpl; | ||
|
|
||
| @Component( | ||
| service = TransformerFactory.class, | ||
| property = { | ||
| "pipeline.type=" + CustomCloudRewriterTransformer.TYPE, | ||
| } | ||
| ) | ||
| public class CustomCloudRewriterTransformer implements TransformerFactory { | ||
|
|
||
| private static final Logger log = LoggerFactory.getLogger(CustomCloudRewriterTransformer.class); | ||
|
|
||
| public static final String TYPE = "custom-linkrewriter"; | ||
|
|
||
| public static final String PATH_PREFIX = "custom"; | ||
|
|
||
|
|
||
| @Reference | ||
| private CustomRunModeConfiguration customRunModeConfiguration; | ||
|
|
||
| @Override | ||
| public TransformerImpl createTransformer() { | ||
| String runmode = customRunModeConfiguration.getRunMode(); | ||
| log.info("current runmode = " + runmode); | ||
| boolean isPublish = "publish".equals(runmode); | ||
| return new TransformerImpl(isPublish); | ||
| } | ||
|
|
||
|
|
||
| protected static class TransformerImpl extends DefaultTransformer { | ||
|
|
||
| private final boolean isPublish; | ||
|
|
||
| public TransformerImpl(boolean isPublish) { | ||
| super(); | ||
| this.isPublish = isPublish; | ||
| } | ||
|
|
||
| @Override | ||
| public void startElement(String uri, String localName, String qName, Attributes attributes) | ||
| throws SAXException { | ||
| AttributesImpl mutableAttributes = | ||
| attributes instanceof AttributesImpl ? (AttributesImpl) attributes | ||
| : null; | ||
| if (isPublish) { | ||
| if ("link".equals(localName)) { | ||
| mutableAttributes = mutableAttributes != null ? mutableAttributes : new AttributesImpl(attributes); | ||
| replaceLinkPaths(mutableAttributes); | ||
| } else if ("script".equals(localName)) { | ||
| mutableAttributes = mutableAttributes != null ? mutableAttributes : new AttributesImpl(attributes); | ||
| replaceScriptPaths(mutableAttributes); | ||
| } | ||
| } | ||
| super.startElement(uri, localName, qName, | ||
| mutableAttributes != null ? mutableAttributes : attributes); | ||
| } | ||
|
|
||
| private void replaceLinkPaths(AttributesImpl attributes) { | ||
| if (attributes.getIndex("href") >= 0 && attributes.getIndex("rel") >= 0) { | ||
| String rel = attributes.getValue("rel"); | ||
| if ("preload stylesheet".equals(rel) || "stylesheet".equals(rel)) { | ||
| int index = attributes.getIndex("href"); | ||
| String value = attributes.getValue(index); | ||
| setAttribute(attributes, index, addPathPrefix(value)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void replaceScriptPaths(AttributesImpl attributes) { | ||
| if (attributes.getIndex("src") >= 0) { | ||
| int index = attributes.getIndex("src"); | ||
| String value = attributes.getValue(index); | ||
| setAttribute(attributes, index, addPathPrefix(value)); | ||
| } | ||
| } | ||
|
|
||
| private String addPathPrefix(String url) { | ||
| return "/" + PATH_PREFIX + url; | ||
| } | ||
|
|
||
| private void setAttribute(AttributesImpl attributes, int index, String value) { | ||
| String attrUri = attributes.getURI(index); | ||
| String attrLocalName = attributes.getLocalName(index); | ||
| String attrQName = attributes.getQName(index); | ||
| String attrType = attributes.getType(index); | ||
| attributes.setAttribute(index, attrUri, attrLocalName, attrQName, attrType, value); | ||
| } | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
...e/src/main/java/com/adobe/cq/forms/core/components/it/service/rewriter/CustomRunMode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.adobe.cq.forms.core.components.it.service.rewriter; | ||
|
|
||
| import org.osgi.service.metatype.annotations.AttributeDefinition; | ||
| import org.osgi.service.metatype.annotations.ObjectClassDefinition; | ||
|
|
||
| @ObjectClassDefinition(name = "Runmode OSGI Configuration", description = "Configuration for Identifying Run Mode") | ||
| public @interface CustomRunMode { | ||
|
|
||
| @AttributeDefinition(name = "Runmode Information", description = "Runmode Info") | ||
| String runmode_info() default "default"; | ||
| } |
25 changes: 25 additions & 0 deletions
25
...va/com/adobe/cq/forms/core/components/it/service/rewriter/CustomRunModeConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package com.adobe.cq.forms.core.components.it.service.rewriter; | ||
|
|
||
| import org.osgi.service.component.annotations.Activate; | ||
| import org.osgi.service.component.annotations.Component; | ||
|
|
||
| @Component( | ||
| service = CustomRunModeConfiguration.class | ||
| ) | ||
| public class CustomRunModeConfiguration { | ||
|
|
||
| private CustomRunMode customRunMode; | ||
|
|
||
| @Activate | ||
| public void activate(CustomRunMode customRunMode) { | ||
| this.customRunMode = customRunMode; | ||
| } | ||
|
|
||
| public String getRunMode() { | ||
| if (customRunMode != null) { | ||
| return customRunMode.runmode_info(); | ||
| } else { | ||
| return "default"; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace prefix path with your path