Hi Team,
If a component is deleted from a live copy page, AEM replaces it with a "ghost" component ( wcm/msm/components/ghost ).
As per business requirements,
I have to delete this Ghost component on publish server only but It should remain in the page model on AEM author to ensure that users can re-instate deleted components as needed.
<div data-cq-data-path="/content/weretail/home/livecopysample/jcr:content/root/decorativepanel/content/row/grid/text" class="cq-Editable-dom"><div class="aem-placeholder">Ghost Component<br><strong>wcm/msm/components/ghost</strong></div><div></div></div>
Solved! Go to Solution.
Views
Replies
Total Likes
@maheswaraiah_m You can execute your code conditionally by fetching runmode as below
import org.apache.felix.scr.annotations.Component; import org.apache.sling.settings.SlingSettingsService; @Component public class MyService { @Reference private SlingSettingsService slingSettingsService; private boolean isPublish() { return this.slingSettingsService.getRunModes().contains("publish"); } }
Hi @maheswaraiah_m,
Please check similar thread here: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/issue-with-wcm-msm-compone...
Hope that helps!
Regards,
Santosh
Thanks @SantoshSai
I guess it won't work as I am not able to see any ".ghost" class.
Reference: <div data-cq-data-path="/content/weretail/home/livecopysample/jcr:content/root/decorativepanel/content/row/grid/text" class="cq-Editable-dom"><div class="aem-placeholder">Ghost Component<br><strong>wcm/msm/components/ghost</strong></div><div></div></div>
@maheswaraiah_m In DOM structure could you please check - there must be some LayoutContainer where resources are listed based on that you can go for custom implementation as mentioned in above thread.
this is the sling:resourceType for that componet. sling:resourceType :wcm/msm/components/ghost
could you please help me with that how to return the resource list except for the ghost resource?
protected List<ResourceListItemImpl> readItems() { return getChildren().stream() .map(res -> new ResourceListItemImpl(linkManager, res, getId(), component)) .collect(Collectors.toList()); }
I have one query: If we do like this, why does it filter out on publish instance, and why not in the author instance?
@maheswaraiah_m You can execute your code conditionally by fetching runmode as below
import org.apache.felix.scr.annotations.Component; import org.apache.sling.settings.SlingSettingsService; @Component public class MyService { @Reference private SlingSettingsService slingSettingsService; private boolean isPublish() { return this.slingSettingsService.getRunModes().contains("publish"); } }
@maheswaraiah_m A side question: It seems the method "getChildren()" is selfcreated. As far as I understood you do not want to keep the content from ghos component. Would it be an option to delete this resource during executing "getChildren()" only on publish instance?
Another option would be creating an event lister which calls a service which removes all resource of ghost components. You can using sql2 to find all occurences.
Hi @maheswaraiah_m,
the best way to deal with this is to override the layout container class through a delegation pattern and return the resource list based on run mode as told in the above components.
more on customizing the logic: https://experienceleague.adobe.com/docs/experience-manager-core-components/using/developing/customiz...
more on delegation pattern: https://github.com/adobe/aem-core-wcm-components/wiki/Delegation-Pattern-for-Sling-Models
Thank you.
-Sravan