SaaS CMS has officially launched! Learn more now.

Hieu Nguyen Trung
Feb 23, 2017
  4896
(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 Concepts and Terminologies

Whether you're a new user of Optimizely CMS or a veteran who have been through the evolution of it, the SaaS CMS is bringing some new concepts and...

Patrick Lam | Jul 15, 2024

How to have a link plugin with extra link id attribute in TinyMce

Introduce Optimizely CMS Editing is using TinyMce for editing rich-text content. We need to use this control a lot in CMS site for kind of WYSWYG...

Binh Nguyen Thi | Jul 13, 2024

Create your first demo site with Optimizely SaaS/Visual Builder

Hello everyone, We are very excited about the launch of our SaaS CMS and the new Visual Builder that comes with it. Since it is the first time you'...

Patrick Lam | Jul 11, 2024

Integrate a CMP workflow step with CMS

As you might know Optimizely has an integration where you can create and edit pages in the CMS directly from the CMP. One of the benefits of this i...

Marcus Hoffmann | Jul 10, 2024