Get Specific Epi Server Form Elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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