Hi,
I've stumbled upon some problems with EPiForms together with the Content API. The template and assets described in (https://world.episerver.com/documentation/developer-guides/content-delivery-api/content-delivery-api-and-episerver-forms/) are not present in the response (unless we explicitly ask for the form's specific ID). However, we utilize friendly URLs in our SPA so this isn't an option.
It seems like the cause to this is that we've also implemented the CustomContentAreaPropertyModel (described in https://world.episerver.com/documentation/developer-guides/content-delivery-api/how-to-customize-data-returned-to-clients/) to expand all content areas. We've checked the dll:s with ILSpy and found some differences with the previous implementation and managed to get it working by rewriting the expand behaviour like so:
protected override IEnumerable<ContentApiModel> ExtractExpandedValue(CultureInfo language)
{
List<ContentApiModel> expandedValue = new List<ContentApiModel>();
IEnumerable<ContentReference> contentReferences = from x in base.Value
where x.ContentLink != null
select new ContentReference(x.ContentLink.Id.Value);
List<IContent> source = _contentLoaderService.GetItems(contentReferences, language).ToList();
var principal = base.ExcludePersonalizedContent ? _principalAccessor.GetAnonymousPrincipal() : _principalAccessor.GetCurrentPrincipal();
source.Where((IContent x) => _accessEvaluator.HasAccess(x, principal, AccessLevel.Read)).ToList().ForEach(delegate (IContent fc)
{
expandedValue.Add(GetMapper(_contentModelMapper, fc).TransformContent(fc, base.ExcludePersonalizedContent, "*"));
});
return expandedValue;
}
public static IContentModelMapper GetMapper(IContentModelMapper mapper, IContent content)
{
if (!(mapper is ContentModelMapperBase))
{
return mapper;
}
return ServiceLocator.Current.GetInstance<IContentModelMapperFactory>().GetMapper(content);
}
Don't know if this helps anyone or if EPiServer might have an answer to why this is, maybe the CustomContentAreaPropertyModel-functionality was written before CD.Forms was developed?