In CQ5, when a form (sling:resourceType=foundation/components/form/start
) is added to a page, CQ5 automatically adds a form_end_xyz
(sling:resourceType=foundation/components/form/end
) component after that component:
How is this accomplished?
There is a com.day.cq.wcm.foundation.forms.impl.FormParagraphPostProcessor
OSGi service implementing SlingPostProcessor
. Such processor is invoked every time there is a POST HTTP request modyfing the Sling resource. It's invoked before the commit, so it's possible to change the desired modification, cancel it (throwing an exception), etc.
In this case, the processor adds the missing form_end_...
node.
This presentation describes Sling POST handling pretty well.
The form end is added/removed by the fixStructure()
method of the FormParagraphPostProcessor class(/libs/foundation/src/impl/src/main/java/com/day/cq/wcm/foundation/forms/impl/FormParagraphPostProcessor.java
). This post processor listens to modifications of CQ Pages. Upon finding a form resource in the modified page's paragraph system, it will create/remove the form end paragraphs accordingly.
The following is the code snippet from FormParagraphPostProcessor.java
.
if ( ResourceUtil.isA(res, FormsConstants.RT_FORM_BEGIN)
|| ResourceUtil.isA(res, FormsConstants.RT_FORM_END)) {
if ( FormsHelper.checkFormStructure(res) != null ) {
logger.debug("Fixed forms structure at {}", contentResource.getPath());
}
}else {
fixStructure(res);
}
You may refer to the following links which would elicit how the form_end is added, and issues with extending the form start component.