Prevent TinyMce from rewritting simple urls

Vote:
 

Hey all,

We recently upgraded our .Net solution to CMS 12 which seems to have changed the behaviour of our TinyMce editor and how it transforms internal links.

  • sampleurl.html (the intended url)
  • /EPiServer/CMS/Content/Shop/sampleurl,,72193/?epieditmode=false (what the url is transformed to, after upgrade)

Our Custom Config:

    internal static class CustomTinyMceConfig
    {
        public static IServiceCollection ConfigureTinyMce(this IServiceCollection services)
        {
            services.Configure<TinyMceConfiguration>(config =>
            {
                config.Default()
                    .AddPlugin("media wordcount anchor link code table")
                    .Toolbar("formatselect | epi-personalized-content anchor link numlist bullist indent outdent bold italic underline alignleft aligncenter alignright | image epi-image-editor media code | epi-dnd-processor | removeformat | fullscreen | table | row_props cell_props row_after row_before delete_row col_after col_before delete_col split_cells merge_cells")
                    .AddSetting("image_caption", true)
                    .AddSetting("image_advtab", true)
                    .InitializationScript("/ClientResources/js/tinymce/custom-init.js");
            });

            return services;
        }
    }

custom-init.js

define([], function () {
    return function (settings) {
        return Object.assign(settings, {
            /* 
             * call back to overwrite tinymce and epi urlconvert implementations for internal links
             * 
             * links defined in TinyMCE CMS blocks should take the form:
             *      href="{ PAGE_SIMPLE_URL }.html"
             *      
             * */
            urlconverter_callback: function (url, node, on_save) {
                var rval = url;

                // convert internal urls only
                if (url.includes('.html') && !url.includes('http')) {
                    rval = url.replace(/^.*[\\\/]/, '');;
                }

                return rval;
            }
        });
    };
});

Any ideas what could be causing this issue? Have tried quite a few things, including adding the "convert_url":false parameter to our custom config, which did not seem to work.

Thank you!

#332706
Edited, Nov 11, 2024 18:35
Vote:
 

Hi,
From what I see you are using a default TinyMCE link plugin for the links, and the issue you described can be reproduced there:



Is it an option for you to use the epi-link plugin instead? It shows the CMS Link modal in that case:



It appears that urlconverter_callback is also executed when using epi-link, so you should be able to continue performing necessary conversions.

#332977
Nov 15, 2024 12:15
Vote:
 

Damien,

Thank you for your response! 

So it looks like that wasn't the exact issue, but it did lead me to figure out exactly how we were setting those plugins, so I removed our custom code and defined the settings through our .NET project instead, which actually seemed to work! For anyone in the future who has this same issue, here is the new code that doesn't transform the URLs:

        public static IServiceCollection ConfigureTinyMce(this IServiceCollection services)
        {
            services.Configure<TinyMceConfiguration>(config =>
            {
                config.Default()
                    .AddPlugin("media wordcount anchor link code table")
                    .Toolbar("formatselect | epi-personalized-content anchor link numlist bullist indent outdent bold italic underline alignleft aligncenter alignright | image epi-image-editor media code | epi-dnd-processor | removeformat | fullscreen | table | tablerowprops tablecellprops tableinsertrowbefore tableinsertrowafter tabledeleterow tableinsertcolafter tableinsertcolbefore tabledeletecol tablesplitcells tablemergecells")
                    .AddSetting("convert_urls", false)
                    .AddSetting("relative_urls", false)
                    .AddSetting("remove_script_host", true)
                    .AddSetting("document_base_url", string.Empty);
            });

            return services;
        }
#333107
Nov 18, 2024 17:32
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.