There are two main approaches to handling a custom field when creating a site live copy in Adobe AEM:
-
Prompt the user to enter the custom field value during the site copy process. This is the simplest approach and can be implemented using the standard site copy dialog. However, it requires the user to manually enter the value of the custom field, which can be inconvenient if the value is always the same or can be easily derived from another field.
-
Automatically populate the custom field value based on the source site or other criteria. This approach can be more convenient for the user, but it requires some additional development effort. You will need to create a custom dialog or extend the standard site copy dialog to capture the value of the custom field. You can then use this value to populate the custom field on the destination site.
Here are some specific examples of how to implement each approach:
Approach 1: Prompt the user to enter the custom field value
To prompt the user to enter the custom field value during the site copy process, you can add a new field to the standard site copy dialog. This field can be a text field, a dropdown list, or any other type of field that is appropriate for the custom field value.
Here is an example of how to add a new text field to the standard site copy dialog:
<dialog jcr:primaryType="nt:dialog" xmlns="https://www.adobe.com/cq/experience-manager/editor-dialogs/dialog" xmlns:cq="https://www.adobe.com/cq/experience-manager/editor-dialogs/cq/element">
<items>
<textfield
name="office"
label="Office"
required="true" />
</items>
</dialog>
This code will add a new text field called "office" to the standard site copy dialog. The user will be required to enter a value for this field before the site copy can be completed.
Approach 2: Automatically populate the custom field value
To automatically populate the custom field value based on the source site or other criteria, you will need to create a custom dialog or extend the standard site copy dialog. You can then use the value of the custom field on the source site to populate the custom field on the destination site.
Here is an example of how to extend the standard site copy dialog to automatically populate the "office" field:
<cq:dialog
jcr:primaryType="nt:dialog"
xmlns="https://www.adobe.com/cq/experience-manager/editor-dialogs/dialog"
xmlns:cq="https://www.adobe.com/cq/experience-manager/editor-dialogs/cq/element"
modelName="liveCopyDialog"
scriptingType="cq/xdialog">
<items>
<textfield
name="office"
label="Office"
valueExpr="beans.sourceSite.get('jcr:title')" />
</items>
</cq:dialog>
The best approach for you will depend on your specific requirements. If you want a simple solution that requires minimal development effort, then Approach 1 is a good option. However, if you need a more flexible solution that can automatically populate the custom field value, then Approach 2 is a better choice.
Kautuk Sahni