Copied to clipboard

Flag this post as spam?

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


  • Nirmit 24 posts 97 karma points
    Mar 31, 2015 @ 07:24
    Nirmit
    0

    Extending RTE property value converter

    Hi,

    I have a specific requirement to extend existing RteMacroRenderingValueConverter (or create a new convertor for RTE Datatype). I have created a tinymce-plugin similar to Umbraco Link plugin which allows user to add a Product link. (i.e, user can insert a product-link for product code=123 as <a href="{\ProductLink:ProductCode=123}">Product Page</a> ) Now I want to get it converted to actual link (i.e, http://my.domain.com/{current-culture}/Product/Details/123) while rendering the page.

    The challenge I have is Umbraco does not allow more than one convertor per property.

    So wondering if there is any way to achieve this functionality.

    Many thanks in advance.

    Regards,
    Nirmit

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Mar 31, 2015 @ 08:24
    Dave Woestenborghs
    101

    Hi Nirmit,

    I think you need to create your own value convertor for this.

    To remove the default value convertor for the Rte you can use this code :

     public class UmbracoEvents : ApplicationEventHandler
     {
           protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {            
                PropertyValueConvertersResolver.Current.RemoveType<TinyMceValueConverter>();          
            }
    }

    Now you can create your own implementation of the TinyMceValueConvertor.

    A good starting point is the source of the default one :

    https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/Umbraco.Core/PropertyEditors/ValueConverters/TinyMceValueConverter.cs

    Dave

  • Nirmit 24 posts 97 karma points
    Apr 01, 2015 @ 03:32
    Nirmit
    0

    Thanks dave for the suggestion. It solved my problem. :)

  • Comment author was deleted

    May 13, 2015 @ 22:04

    +1, Had to use this today :)

  • Jesse Andrews 191 posts 716 karma points c-trib
    Oct 31, 2018 @ 18:23
    Jesse Andrews
    2

    This approach generally works, but I encountered issues when there were macros in the rich text editors. To get around that, I replaced RteMacroRenderingValueConverter instead of TinyMceValueConverter. There are a couple caveats to be aware of.

    1. RteMacroRenderingValueConverter is in the Umbraco.Web namespace and not Umbraco.Core like the others.
    2. The modified version of the RteMacroRenderingValueConverter will need to return an IHtmlString instead of a string. I'm pretty sure the DefaultPropertyValueConverter attribute causes the TinyMceValueConverter to run against the data after the RteMacroRenderingValueConverter does its thing. Unfortunately, it's an internal attribute and so can't be incorporated into custom code.
Please Sign in or register to post replies

Write your reply to:

Draft