Broken recalculate function in editor.js

021

Well-known member
Affected version
2.2.9
When I try to extend the editor toolbar, I get the following error: TypeError: can't access property "filter", buttons is undefined

How do I try to extend the editor toolbar:
JavaScript:
const editor = XF.Element.getHandler(this.$form.find('.js-editor'), 'editor')
editor.buttonManager.adjustToolbar('toolbarButtons', ( buttons, name, manager ) => {
    return buttons // do nothing, just return buttons
})

You obviously need to rewrite the code of the recalculate function, because there is such nonsense...
JavaScript:
// remove disallowed buttons
for (i = 0; i < removeList.length; i++)
{
    remove = removeList[i];

    for (toolbarKey in this.toolbars) // <- toolbarKey is key of toolbars object
    {
        if (this.toolbars.hasOwnProperty(toolbarKey)) // <- check is toolbarKey is key of toolbars object?
        {
            for (group in this.toolbars[toolbarKey]) // <- group is key of toolbars[toolbarKey]
            {
                if (this.toolbars[toolbarKey].hasOwnProperty(group)) // <- check is group is key of toolbars[toolbarKey]?!
                {
                    this.toolbars[toolbarKey][group]['buttons'] = removeFromButtons(this.toolbars[toolbarKey][group]['buttons'], remove);
                }
            }
        }
    }
    for (dropdownKey in this.dropdowns) // <- dropdownKey is key of dropdowns
    {
        if (this.dropdowns.hasOwnProperty(dropdownKey)) // <- check is dropdownKey is key of dropdowns?
        {
            this.dropdowns[dropdownKey] = removeFromButtons(this.dropdowns[dropdownKey], remove);
        }
    }
}

And the toolbars object does not look like this function works with it.
 
Top Bottom