Episerver

Content Provider Nuances

Stuart Blackler

(@im5tu | im5tu.io | slid.es/im5tu/epi-content-providers)

Why Custom Content Providers?

  • Connecting to external content
    • Youtube (github.com/episerver/YouTubeContentProvider)
    • File System (github.com/jbearfoot/LocalMediaProvider)

 

  • Cloning content trees (github.com/episerver/AlloyDemoKit)

What do we need?

  • Content Types
  • Content Providers
    • Provider Mapping
    • Routing (including controllers/views etc)
  • Descriptors
    • Component Descriptor
    • Content Repository Descriptor
    • UI Descriptor
  • Search Providers

Nuance #1 - Repository Keys

  • Can fail silently
  • Must be the same everywhere:
    • Component (add setting named: repositoryKey)
    • Content Repository Descriptor Base (key)
    • Content Providers (ProviderKey)
    • Content Search Provider Base (Area/Category)

  • Ensure lowercase
    • This bug has possibly been fixed
  • Use a string constant

Nuance #2 - The Save Action

  • Not the flags you're looking for

 

  • Usually a few key values

 

  • Get the correct values by enumeration

Nuance #3 - Status Transitions

  • Not Created isn't real
  • IStatusTransitionEvaluator is your friend
internal sealed class MyContentProvider : ContentProvider
{
    protected IStatusTransitionEvaluator StatusTransitionEvaluator { get; }

    public sealed override ContentReference Save(IContent content, SaveAction action)
    {
        var convertedContent = content as IVersionable;
        // ... code ...
        var newStatus = StatusTransitionEvaluator.Evaluate(convertedContent, action);
        if (newStatus.IsStatusChange())
        {
            convertedContent.Status = newStatus.NextStatus;
        }
        // ... code ...
    }
}

Nuance #4 - Multi-Language

  • Setting the out parameter on LoadChildrenReferencesAndTypes
    • Content items should have languageSpecific set to true
    • Content folders should have languageSpecific set to false

 

  • Folders are not language specific (webhelp.episerver.com/latest/platform/folders.htm)

 

  • Use ILanguageBranchRepository to list all/enabled languages (if needed)

Nuance #5 - Search Areas

  • Related to the search text box on the fly out menus

 

  • Requires an implementation of ContentSearchProviderBase<T,T>

 

  • Configured in the implementation of ContentRepositoryDescriptorBase
    • ​public override string SearchArea => Key;

 

  • Gets called a lot if not set

My Top Tip

  • Caching is a pain for debugging, try this:

#if My_Compiler_Switch
    protected sealed override void SetCacheSettings(ContentReference contentReference, 
    IEnumerable<GetChildrenReferenceResult> children, CacheSettings cacheSettings)
    {
        cacheSettings.CancelCaching = true;
        base.SetCacheSettings(contentReference, children, cacheSettings);
    }
    protected sealed override void SetCacheSettings(ContentReference parentLink, string urlSegment,
     IEnumerable<MatchingSegmentResult> childrenMatches, CacheSettings cacheSettings)
    {
        cacheSettings.CancelCaching = true;
        base.SetCacheSettings(parentLink, urlSegment, childrenMatches, cacheSettings);
    }
    protected sealed override void SetCacheSettings(IContent content, CacheSettings cacheSettings)
    {
        cacheSettings.CancelCaching = true;
        base.SetCacheSettings(content, cacheSettings);
    }
#endif

Thanks for listening!

Slides: slid.es/im5tu/epi-content-providers

Questions: @im5tu everywhere

Episerver Content Providers

By Stuart Blackler

Episerver Content Providers

A talk around the use of custom content providers within Episerver, their benefits, implementation and the pitfalls and nuances of using them.

  • 1,985