Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ollie Storey 17 posts 172 karma points
    Sep 17, 2019 @ 10:53
    Ollie Storey
    0

    Custom Property Editor to save value as IEnumerable<IPublishedElement>

    Hey all,

    I am trying to make a custom property editor which extends the nested content property editor.

    It's essentially, the exact same. The only difference is that instead of using the overlayService to show the overlay as standard I use the editorService and open up a blade. In the blade I format the data differently, trying to improve the content editing experience.. blah blah blah.

    The problem is that although it calls the same addNode() method in my angular controller as the standard nested content controller would, the generated model recognises my properties which use the datatype as JToken rather than an IEnumberable<IPublishedContent>.

    What I would like to do is either:

    Cast my JToken property to an IEnumerable<IPublishedElement>

    or

    Save my property in the same way that nested content does so that the generated model recognises the property as an IEnumerable<IPublishedElement> in the first place.

    But I have made little progress so far and any help would be fantastic!

    v8.1.3

  • Marc Goodson 2157 posts 14435 karma points MVP 9x c-trib
    Sep 17, 2019 @ 13:12
    Marc Goodson
    100

    Hi Ollie

    It is the job of a 'PropertyValueConverter' to take a saved value of a property editor and convert it to something useful like IPublishedContent.

    You create a c# class that implements IPropertyValueConverter there is a base implementation in the core here:

    https://github.com/umbraco/Umbraco-CMS/blob/3bfd9b71e290354744d677440983ecd06c5c0788/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs

    You determine in the implementation which propertyType to register your converter for... (so because you have created a new version of the Nested content implementation there isn't currently a registered property value converter for it, which is why you are seeing raw values and not IPublishedContent)

    So a good starting point for you would be the existing NestedContentValueConverters

    There is a 'ManyValue' Converter here:

    https://github.com/umbraco/Umbraco-CMS/blob/3bfd9b71e290354744d677440983ecd06c5c0788/src/Umbraco.Web/PropertyEditors/ValueConverters/NestedContentManyValueConverter.cs

    A 'Single' Converter here:

    https://github.com/umbraco/Umbraco-CMS/blob/3bfd9b71e290354744d677440983ecd06c5c0788/src/Umbraco.Web/PropertyEditors/ValueConverters/NestedContentSingleValueConverter.cs

    and a both inherit from a base converter for NestedContent:

    https://github.com/umbraco/Umbraco-CMS/blob/3bfd9b71e290354744d677440983ecd06c5c0788/src/Umbraco.Web/PropertyEditors/ValueConverters/NestedContentValueConverterBase.cs

    Hopefully if you've only changed the front end implementation, all you need to do is create new converters which inherit from these and override the IsConverter(IPublishedPropertyType propertyType) so it looks up the alias of your new editor

    return publishedProperty.EditorAlias.InvariantEquals("your.propertyeditor.alias");

    regards

    Marc

  • Ollie Storey 17 posts 172 karma points
    Sep 17, 2019 @ 13:17
    Ollie Storey
    0

    Marc, you are my hero! H5YR

    I will give that a go, sounds like the solution to me

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies