You can extend any core component or customize functionality.
Try like this:
Step 1: Create an Interface to extend ContentFragment class and add a method to return path
Step 2: Implement the class , use Delegation
==== Declare an Interface to ContentFragment Extention Class =========
import com.adobe.cq.wcm.core.components.internal.models.v1.contentfragment;
/**
* An extension to the AEM Core Component ContentFragment
*/
public interface ContentFragmentExtention extends ContentFragment {
default String contentFragmentPath() {
throw new UnsupportedOperationException();
}
}
Step2:
==== Implementation your interface ContentFragmentExtention / Class =========
/**
* An extension to the AEM Core Component ContentFragment
*/
@Model(
adaptables = SlingHttpServletRequest.class,
adapters = { ContentFragmentExtention.class, ContentFragment.class, ComponentExporter.class },
resourceType = ContentFragmentExtentionImpl.RESOURCE_TYPE
)
@3484101(
name = ExporterConstants.SLING_MODEL_EXPORTER_NAME,
extensions = ExporterConstants.SLING_MODEL_EXTENSION
)
public class ContentFragmentExtentionImpl implements ContentFragmentExtention {
public static final String RESOURCE_TYPE = "<path to your proxy ContentFragment path> /apps/project/proxy/componetns/contentfragment";
@1961677 @2434638(type = ResourceSuperType.class)
@Delegate(excludes = DelegationExclusion.class)
private ContentFragment contentFragment;
@ValueMapValue
private String contentFragmentPath; // This is a new property that we are introducing
/**
* implement your method
*
* @2007960 <your path>
*/
@9944223
public String contentFragmentPath() {
<< Logic to get the path >>
return <Path to contentfragment>; //contentFragmentPath
}
}