November Happy Hour will be moved to Thursday December 5th.

Hieu Nguyen Trung
Feb 23, 2017
  5121
(7 votes)

Create data feeds for EPiServer Forms

When working with EPiServer.Forms, you may wonder how to bind custom dynamic data source to Selection element instead of manually input items one by one.

Image chrome_2017-02-23_11-26-28.png

You could first do some search and found a great blog here https://www.epinova.no/en/blog/custom-data-feeds-in-episerver.forms/ , but it's been quite out of date since EPiServer.Forms had many updates since then, for example the IExternalSystemFieldMapping interface is no longer existed.

So, I write this blog for any one who comes with the same idea in mind and wants to know how EPiServer.Forms can be extended and works in various scenarios.

1. Create new data feed class

Create new class and implement EPiServer.Forms.Core.Feed.Internal.IFeed and EPiServer.Forms.Core.IUIEntityInEditView.

The IFeed interface has LoadItems method that you can write your own code to get data for selection block.

But to enable displaying the feed on EditView, you need to implement IUIEntityInEditView as well.

    [ServiceConfiguration(ServiceType = typeof(IFeed))]
    public class CustomFeed : IFeed, IUIEntityInEditView
    {
        public IEnumerable<IFeedItem> LoadItems()
        {
            var feedItems = new List<IFeedItem>();

            feedItems.Add(new FeedItem { Key = "Custom data 1", Value = "1" });
            feedItems.Add(new FeedItem { Key = "Custom data 2", Value = "2" });
            feedItems.Add(new FeedItem { Key = "Custom data 3", Value = "3" });

            return feedItems;
        }

        public string ID
        {
            get { return "EDA3BFDF-3EB3-4932-A484-C244FAC55851"; }
        }

        public string Description
        {
            get { return "Custom data source"; }
            set { }
        }

        public string ExtraConfiguration { get; }

        public string EditViewFriendlyTitle
        {
            get { return Description; }
        }

        public bool AvailableInEditView
        {
            get { return true; }
        }
    }

2. Have a feed provider

To know which feed will be displayed, the IFeedProvider must be implemented.

    public class FeedProvider : IFeedProvider
    {
        public IEnumerable<IFeed> GetFeeds()
        {
            return ServiceLocator.Current.GetAllInstances<IFeed>();
        }
    }

3. Build your project and check in EditView

Image chrome_2017-02-23_11-46-27.png

Image chrome_2017-02-23_11-47-48.png

Current EPiServer.Forms used in this blog is v4.4.1

Feb 23, 2017

Comments

Please login to comment.
Latest blogs
Optimizely SaaS CMS + Coveo Search Page

Short on time but need a listing feature with filters, pagination, and sorting? Create a fully functional Coveo-powered search page driven by data...

Damian Smutek | Nov 21, 2024 | Syndicated blog

Optimizely SaaS CMS DAM Picker (Interim)

Simplify your Optimizely SaaS CMS workflow with the Interim DAM Picker Chrome extension. Seamlessly integrate your DAM system, streamlining asset...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Optimizely CMS Roadmap

Explore Optimizely CMS's latest roadmap, packed with developer-focused updates. From SaaS speed to Visual Builder enhancements, developer tooling...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Set Default Culture in Optimizely CMS 12

Take control over culture-specific operations like date and time formatting.

Tomas Hensrud Gulla | Nov 15, 2024 | Syndicated blog