aem-core-wcm-components icon indicating copy to clipboard operation
aem-core-wcm-components copied to clipboard

Embeddable not included in Embed JSON export

Open HitmanInWis opened this issue 8 months ago • 0 comments

Bug present as of version: 2.24.7-SNAPSHOT

When the Embed component is used with an Embeddable (e.g. YouTube) the JSON model export does not include the embeddable, and thus omits all relevant details required to render in a non-AEM system.

This can be remediated with the following steps:

  • Update Embeddable interface to extend ComponentExporter
  • Update YouTube model to specify explicit resourceType and then add adapters of Embeddable.class, ComponentExporter.class
  • Add an isConfigured function to the Embeddable interface
  • Add the following code to EmbedImpl
    @Override
    public @Nullable Embeddable getEmbeddable() {
        if (embeddable == null && StringUtils.isNotBlank(embeddableResourceType)) {
            Resource embeddableResource = new CoreResourceWrapper(resource, embeddableResourceType);
            embeddable = modelFactory.getModelFromWrappedRequest(request, embeddableResource, Embeddable.class);
            if (embeddable == null) {
                LOGGER.warn("Unable to cast embed {} to embeddable type {}", resource.getPath(), embeddableResourceType);
            }
        }
        return embeddable != null && embeddable.isConfigured() ? embeddable : null;
    }

HitmanInWis avatar Jun 06 '24 19:06 HitmanInWis