Copied to clipboard

Flag this post as spam?

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


  • Thomas Won Nyheim 33 posts 145 karma points
    Sep 13, 2019 @ 14:55
    Thomas Won Nyheim
    0

    Porting a custom property editor fomr V7 to V8

    Trying to port a custom property editor to V8 from V7.

    Been looking at https://our.umbraco.com/forum/umbraco-8/96241-rendering-custom-property-editor-in-v8 but I still seem like I'm getting basic errors.

    Examples: 'SimplePropertyValueConverter.IsConverter(PublishedPropertyType)': no suitable method found to override

    'PublishedPropertyType' does not contain a definition for 'PropertyEditorAlias' and no accessible extension method 'PropertyEditorAlias' accepting a first argument of type 'PublishedPropertyType'

    using Umbraco.Core.Models.PublishedContent;
    using Umbraco.Core.PropertyEditors;
    
    namespace Simple
    {
        public class SimplePropertyValueConverter : PropertyValueConverterBase
        {
            public override bool IsConverter(PublishedPropertyType propertyType)
            {
                return propertyType.PropertyEditorAlias != null && propertyType.PropertyEditorAlias.Equals("Simple.Editor");
            }
        }
    }
    

    From what I understand from that other forum thread, this should be working without any issues.

  • Paul Seal 524 posts 2889 karma points MVP 7x c-trib
    Sep 13, 2019 @ 22:42
    Paul Seal
    1

    Hi Thomas

    I have a property editor package which is available for v7 and v8

    Here is the Property Value Converter for v7: https://github.com/prjseal/Giphy-Property-Editor/blob/umbraco-v7/GiphyPropertyEditorUmbraco7/PropertyValueConverters/GiphyPropertyValueConverter.cs

    using System;
    using Umbraco.Core.Models.PublishedContent;
    using Umbraco.Core.PropertyEditors;
    
    namespace GiphyPropertyEditorUmbraco7.PropertyValueConverters
    {
        public class GiphyPropertyValueConverter : PropertyValueConverterBase
        {
            /// <summary>
            /// Gets a value indicating whether the converter supports a property type.
            /// </summary>
            /// <param name="propertyType">The property type.</param>
            /// <returns>A value indicating whether the converter supports a property type.</returns>
            public bool IsConverter(PublishedPropertyType propertyType)
            {
                return propertyType.PropertyEditorAlias.Equals("GiphyPropertyEditorUmbraco7");
            }
    
            /// <summary>
            /// Gets the type of values returned by the converter.
            /// </summary>
            /// <param name="propertyType">The property type.</param>
            /// <returns>The CLR type of values returned by the converter.</returns>
            public Type GetPropertyValueType(PublishedPropertyType propertyType)
            {
                return typeof(string);
            }
        }
    }
    

    And here is the Property Value Converter for v8: https://github.com/prjseal/Giphy-Property-Editor/blob/master/GiphyPropertyEditor/PropertyValueConverters/GiphyPropertyValueConverter.cs

    using System;
    using Umbraco.Core.Models.PublishedContent;
    using Umbraco.Core.PropertyEditors;
    
    namespace GiphyPropertyEditor.PropertyValueConverters
    {
    
        public class GiphyPropertyValueConverter : PropertyValueConverterBase
        {
    
            /// <summary>
            /// Gets a value indicating whether the converter supports a property type.
            /// </summary>
            /// <param name="propertyType">The property type.</param>
            /// <returns>A value indicating whether the converter supports a property type.</returns>
            public override bool IsConverter(PublishedPropertyType propertyType)
            {
                return propertyType.EditorAlias == "GiphyPropertyEditor";
            }
    
            /// <summary>
            /// Gets the type of values returned by the converter.
            /// </summary>
            /// <param name="propertyType">The property type.</param>
            /// <returns>The CLR type of values returned by the converter.</returns>
            public override Type GetPropertyValueType(PublishedPropertyType propertyType)
            {
                return typeof(string);
            }
    
        }
    
    }
    

    The differences I can see are in the v8 version we are using the override keyword in the methods. And I don't know if it makes a difference but instead of .Equals the v8 version of mine is using ==

    Hopefully this will help you.

    Cheers

    Paul

  • Thomas Won Nyheim 33 posts 145 karma points
    Sep 16, 2019 @ 10:06
    Thomas Won Nyheim
    0

    Thank you for your response, however it seems that U8 does not like the override

    When I remove and use the code seems to be without errors.

    return propertyType.EditorAlias == "GiphyPropertyEditor"; 
    

    instead of

    return propertyType.PropertyEditorAlias.Equals("GiphyPropertyEditorUmbraco7");
    

    which returns Severity Code Description Project File Line Suppression State Error CS1061 'PublishedPropertyType' does not contain a definition for 'PropertyEditorAlias' and no accessible extension method 'PropertyEditorAlias' accepting a first argument of type 'PublishedPropertyType' could be found (are you missing a using directive or an assembly reference?)

    I will check it out further, thank you

Please Sign in or register to post replies

Write your reply to:

Draft