I am using core wcm Experience Fragment (com.adobe.cq.wcm.core.components.models.ExperienceFragment) which I am extending in my own code base via the @Delegate pattern. When author adds an experience fragment on a page / when request is made to export the XF as json, I need to check all variations of given XF, filter them based on tag and export one of the variations which matches my tag as JSON. How can I rewrite the current request to generate the content of a XF variation in the sling model?
I am able to get paths of all variations from given XF but when I try to adaptTo(ExperienceFragment.class) it is always null. I can adaptTo(ValueMap.class) from which I can see the template used by that variation but that is not helpful as that does not give me exported items. I tried creating a new temporary page using PageManager from given XF template however running into replication errors that way.
Is there a way to export an XF variation of our choosing in Sling model when request is made for a different variation of the same XF?
I noticed there's a private getChildren() method on the core XF which is used to get all exported items and which relies on getLocalizedFragmentVariationPath() method in the same core XF class but even if I override the getLocalizedFragmentVariationPath method to return path of a different variation the JSON items exported are those of the original experience fragment, not the modified variation.