Magento 2 – How to Extend WYSIWYG setup.js to Add Language Settings

extendlanguagemagento2requirejswysiwyg

i need to modify:

setup: function (mode) {
        if (this.config['widget_plugin_src']) {
            tinyMCE.PluginManager.load('magentowidget', this.config['widget_plugin_src']);
        }

        if (this.config.plugins) {
            this.config.plugins.each(function (plugin) {
                tinyMCE.PluginManager.load(plugin.name, plugin.src);
            });
        }

        if (jQuery.isReady) {
            tinyMCE.dom.Event.domLoaded = true;
        }

        tinyMCE.init(this.getSettings(mode));
    },

of the mage/adminhtml/wysiwyg/tiny_mce/setup.js file.
I created a requirejs-config.js with this code:

var config = {
"map": {
"*": {
  "mage/adminhtml/wysiwyg/tiny_mce/setup": "js/custom_tinymce_setup"
}

}
};

Magento recognize my file, but i have copied all the content of the setup.js to custom_tinymce_setup.js becouse i could not find the way to only replace that function named above.

If anyone can help me, i'll appreciate it.

Best Answer

If it's usefull to someone, i have made this changes and it worked:

file: /app/design/adminhtml/<'vendor'>/<'theme'>/requirejs-config.js

var config = {
map: {
    "*": {
      "customTinymceSetup": "js/custom_tinymce_setup",
    },
},
deps: [
    'mage/adminhtml/wysiwyg/tiny_mce/setup'
]
};

file: app/design/adminhtml/<'vendor'>/<'theme'>/web/js/custom_tinymce_setup.js

define([
'jquery',
'tinymce',
'mage/adminhtml/wysiwyg/tiny_mce/setup'
], function (jQuery, tinyMCE) {

window.tinyMceWysiwygSetup.prototype.setup = function (mode) {
    if (this.config['widget_plugin_src']) {
        tinyMCE.PluginManager.load('magentowidget', this.config['widget_plugin_src']);
    }

    if (this.config.plugins) {
        this.config.plugins.each(function (plugin) {
            tinyMCE.PluginManager.load(plugin.name, plugin.src);
        });
    }

    if (jQuery.isReady) {
        tinyMCE.dom.Event.domLoaded = true;
    }

    let settings = this.getSettings(mode);
    settings['language'] = "es";

    tinyMCE.init(settings);
    tinyMCE.addI18n({es:{magentowidget:{'insert_widget':'Insertar AplicaciĆ³n'}}});
    tinyMCE.addI18n({es: {magentovariable: {'insert_variable': 'Insertar Variable'}}});
}
});

I called de js from the /app/code/<'vendor'>/<'module'>/view/adminhtml/templates/page/header.phtml file. before the end of file:

<script type="text/javascript">
    require(['customTinymceSetup']);
</script>

Just have to add the es.js files to lib/web/tiny_mce/themes/advanced/langs and lib/web/tiny_mce/langs/

Thanks!