I have a situation where I have a Component Link which contains fields that I'd like to be editable within Experience Manager. Component A contains a link to component B, which has a link to multimedia component C.
Component B has some fields related-ish to Component C. I would like to render C, allow the content author to edit fields in B, and also in A.
Component B has no template. Component A is the only template.
I understand that DXA does not add XpmMetadata to linked components on its own. But I can generate XpmMetadata for this.
So I'm trying to create a helper that does this for me. XpmMetadata Contains five properties:
ComponentTemplateID
ComponentModified
ComponentID
ComponentTemplateModified
IsRepositoryPublished
If I want fields within a linked component to be editable, I'm guessing that ComponentID
is for the linked Component. And I would guess that ComponentModified
is, too.
I can get the ComponentID
, but how do I get the ComponentModified
property?
OR, can I use the ComponentModified
property from "Component A".
I've developed a solution that I think would work, but I'm not 100% sure because I don't know the rules around these fields
Below is the class I'ved added to a helper:
public static class DXAComponentLinkHelper
{
public static IDictionary<string,object> getXpmMetadata(EntityModel entity, Dictionary<string, object> parentXpmData)
{
Dictionary<string, object> xpmMedatadata = new Dictionary<string, object>();
object parentTemplate = null;
object parentCompModified = null;
parentXpmData.TryGetValue("ComponentTemplateID", out parentTemplate);
parentXpmData.TryGetValue("ComponentModified", out parentCompModified);
xpmMedatadata.Add("ComponentID", entity.Id);
xpmMedatadata.Add("ComponentModified", parentCompModified);
xpmMedatadata.Add("ComponentTemplateID", parentTemplate);
xpmMedatadata.Add("ComponentTemplateModified", parentCompModified);
xpmMedatadata.Add("IsRepositoryPublished", false);
return xpmMedatadata;
}
}
Is this a viable solution? is there a better one? How can I XPM-enable inline editing on a linked component without creating a component template?