Try our conversational search powered by Generative AI!

Hieu Nguyen Trung
Feb 23, 2017
  4785
(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 and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog

The A/A Test: What You Need to Know

Sure, we all know what an A/B test can do. But what is an A/A test? How is it different? With an A/B test, we know that we can take a webpage (our...

Lindsey Rogers | Apr 15, 2024

.Net Core Timezone ID's Windows vs Linux

Hey all, First post here and I would like to talk about Timezone ID's and How Windows and Linux systems use different IDs. We currently run a .NET...

sheider | Apr 15, 2024