Copied to clipboard

Flag this post as spam?

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


  • Scott Meysman 5 posts 75 karma points
    Apr 11, 2019 @ 12:58
    Scott Meysman
    0

    Rich text editor formats aren't loaded

    Hello!

    In our current project, Umbraco version 7.14.0, we use rich text editors that can have formats that are loaded in the Stylesheets tab (in the Settings tab). The formats aren't loaded and when clicked in the Content page, the button shows an empty list.

    After some code crawling in the RTEController in the umbraco.controllers.js file, I have discovered that the styleformats property in the RTE config is empty. Then, searching why it is empty, I found that the value *styleFormats* which passes its value to the *styleformats* is also empty (big suprise). Looking further, I found that in this method something goes silently wrong.

    angular.forEach(editorConfig.stylesheets, function (val, key) {
                stylesheets.push(Umbraco.Sys.ServerVariables.umbracoSettings.cssPath + '/' + val + '.css?' + new Date().getTime());
                await.push(stylesheetResource.getRulesByName(val).then(function (rules) {
                    angular.forEach(rules, function (rule) {
                        var r = {};
                        r.title = rule.name;
                        if (rule.selector[0] == '.') {
                            r.inline = 'span';
                            r.classes = rule.selector.substring(1);
                        } else if (rule.selector[0] == '#') {
                            r.inline = 'span';
                            r.attributes = { id: rule.selector.substring(1) };
                        } else if (rule.selector[0] != '.' && rule.selector.indexOf('.') > -1) {
                            var split = rule.selector.split('.');
                            r.block = split[0];
                            r.classes = rule.selector.substring(rule.selector.indexOf('.') + 1).replace('.', ' ');
                        } else if (rule.selector[0] != '#' && rule.selector.indexOf('#') > -1) {
                            var split = rule.selector.split('#');
                            r.block = split[0];
                            r.classes = rule.selector.substring(rule.selector.indexOf('#') + 1);
                        } else {
                            r.block = rule.selector;
                        }
                        styleFormats.push(r);
                    });
                }));
            });
    

    styleFormats is set inside of this Angular promise which returns rules. These rules are looped over with a foreach but in our case the rules are undefined and the rules aren't looped over.

    Here I learned that the assigned stylesheets to the RTE are in fact loaded since the method is hit and the promise does run. The editorconfig.stylesheets contains the stylesheets.

    I tried checking the Stylesheets css for problems and these are fine. I checked our Grid Editors which use RTEs and they seem okay as well. We use LeCoati.LeBlender for those Editors.

    Finally, I checked the getRulesByName method when the RTEController hit it and made up this URL which the method gets with a http request. /umbraco/backoffice/UmbracoApi/Stylesheet/getRulesByName?name=rte

    getRulesByName: function (name) {
                return umbRequestHelper.resourcePromise($http.get(umbRequestHelper.getApiUrl('stylesheetApiBaseUrl', 'GetRulesByName', [{ name: name }])), 'Failed to retrieve stylesheets ');
            }
    

    When I visited the page in the browser, the page was empty which is most likely the problem, since there is nothing to return to the rules. My question is why would this browser page be empty? If you can point me in some possible directions, I would be very grateful.

    Thank you.

  • Scott Meysman 5 posts 75 karma points
    Apr 12, 2019 @ 08:31
    Scott Meysman
    0

    Update:

    The page I visited at /umbraco/backoffice/UmbracoApi/Stylesheet/getRulesByName?name=rte was empty because the cookies weren't present and the call declined with a statuscode of 417. Checking out the call in the developer tools Network section, I see that the call succeeds with a 200 and the Response payload is:

    )]}',[]
    

    This crashes with a SyntaxError because JSON can't parse the result. The array is empty though. I would expect the css data in here. My question has changed from "why is the browser empty" to "why is this result array empty"?

    Thanks!

  • Scott Meysman 5 posts 75 karma points
    Apr 12, 2019 @ 12:20
    Scott Meysman
    0

    Solution:

    So it had nothing to do with Umbraco failing, I was using stylesheets the wrong way. The correct way is explained in this video: https://www.youtube.com/watch?v=0pkKz6YA7aI

    Thanks Paul!

Please Sign in or register to post replies

Write your reply to:

Draft