Umbraco Forms - Get Field Types in Code

Hi,

I am in the process of looking in to how we can update an site created in Umbraco 7 and 8 that use form in a custom IONIC app that one of my colleges wrote a while ago.

I have worked out how to pull the forms them self and dump them as JSON but there a couple of lines of code I am having issues with.

// Get Field Types
FieldTypes fieldTypes = new FieldTypes();
umbForms.fieldTypes = fieldTypes.GetAll();

This looks like it uses a Build in Method in Umbeco 7 and 8 to get the Field Types, But I can’t work out how to do this in 13.

Thanks
Darren

@using Umbraco.Forms.Core
@using Umbraco.Forms.Core.Providers
@using Umbraco.Forms.Web.Models.Backoffice
@inject FieldCollection fieldCollection

    List<BasicFieldType> allFieldTypes = new List<BasicFieldType>();
    foreach (FieldType fieldType in (BuilderCollectionBase<FieldType>)fieldCollection)
    {
        BasicFieldType basicFieldType = new BasicFieldType()
        {
            Id = fieldType.Id,
            Name = fieldType.Name
        };
        allFieldTypes.Add(basicFieldType);
    }

actually more simply…

@using Umbraco.Forms.Core
@using Umbraco.Forms.Core.Providers
@inject FieldCollection _fieldCollection

List<FieldType> list = _fieldCollection.ToList<FieldType>();

Thank you that worked as I would of expected.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.