Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get Specific Epi Server Form Elements
using EPiServer.Core;
using EPiServer.Forms.Core;
using EPiServer.Forms.Core.Models;
using EPiServer.Forms.Helpers.Internal;
using EPiServer.Forms.Implementation.Elements;
using System.Collections.Generic;
using System.Linq;
namespace PixieDigital.EpiServer.Extensions
{
public static class FormExtensions
{
public static IEnumerable<T> GetSpecificFormElements<T>(this FormIdentity formIdentity, bool filteredItemsOnly = true) where T : ElementBlockBase
{
return GetSpecificFormElements<T>(formIdentity.GetFormBlock(), filteredItemsOnly);
}
public static IEnumerable<T> GetSpecificFormElements<T>(this FormContainerBlock formContainerBlock, bool filteredItemsOnly = true) where T : ElementBlockBase
{
if (formContainerBlock != null && formContainerBlock.ElementsArea != null && formContainerBlock.ElementsArea.Items != null && formContainerBlock.ElementsArea.Items.Count() != 0)
{
var formElements = filteredItemsOnly ? formContainerBlock.ElementsArea.FilteredItems : formContainerBlock.ElementsArea.Items;
foreach (var item in formElements)
{
T element = item.ContentLink.GetContent((formContainerBlock as ILocale).Language.Name) as T;
if (element != null)
{
yield return element;
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.