kjac / FormEditor

A form builder editor for Umbraco 7 - let your editors build forms easily with this free package.
MIT License
99 stars 42 forks source link

GetFormModelProperty function not considering compositions #172

Closed joshreid closed 6 years ago

joshreid commented 6 years ago

Hi @kjac

I have found that the GetFormModelProperty function does not consider the possibility of property being in a composition in the contentType.

So I have revised code in ContentHelper.cs below to fix - can give pull request if you want.

public static PropertyType GetFormModelProperty(IContentType contentType)
{
    List<PropertyType> propertyTypes = contentType.PropertyTypes.ToList();
    propertyTypes.AddRange(contentType.CompositionPropertyTypes);

    var property = propertyTypes.FirstOrDefault(p => p.PropertyEditorAlias == FormModel.PropertyEditorAlias);
    return property;
}

Let me know if you need anything else and when you'll repackage - I'll run my custom built dll for now.

kjac commented 6 years ago

Hi @joshreid,

Awesome, thank you!

Just to avoid creating the list if we don't have to, could you try this code and see if that works for you as well?

public static PropertyType GetFormModelProperty(IContentType contentType)
{
  bool IsFormModelPropertyEditor(PropertyType p) => p.PropertyEditorAlias == FormModel.PropertyEditorAlias;

  return contentType.PropertyTypes.FirstOrDefault(IsFormModelPropertyEditor)
         ?? contentType.CompositionPropertyTypes.FirstOrDefault(IsFormModelPropertyEditor);
}
joshreid commented 6 years ago

All good thanks @kjac - yep that's better, and works as expected.

kjac commented 6 years ago

Whoops, this one's in the latest version :) closing it now.