Copied to clipboard

Flag this post as spam?

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


  • mauzilla 19 posts 90 karma points
    Oct 26, 2023 @ 12:00
    mauzilla
    0

    Custom button not showing in tinyMCE toolbar

    Based on numerous posts about this, I have been dabbling with adding a custom button to the RTE. The button simply creates a

    • Item
    into the editor.

    The direction I have taken was to add a new "plugin" to www/umbraco/lib/tinymce/plugins/customlist/plugin.min.js:

    tinymce.PluginManager.add('customlists', (editor, url) => {
        editor.ui.registry.addButton('customlist', {
            text: 'Custom List',
            onAction: () => {
                /* Open window */
                editor.insertContent('&nbsp;<ul class="custom-list"><li>item</li></ul>&nbsp;');
            }
    });
    /* Return the metadata for the help plugin */
    return {
        getMetadata: () => ({
            name: 'customlist',
            url: 'http://exampleplugindocsurl.com'
        })
    };
    });
    

    This is based on the syntax from TinyMCE for the v6 of their editor. In my appsettings.json, I have added the below under the Umbraco.CMS namespace:

    "RichTextEditor": {
      "Plugins": [
        "anchor",
        "charmap",
        "table",
        "customlist"
      ],
      "ValidElements": "+a[id|style|rel|data-id|data-udi|rev|charset|customlist|hreflang|dir|lang|tabindex|accesskey|type|name|href|target|title|class|onfocus|onblur|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup],-strong/-b[class|style],-em/-i[class|style],-strike[class|style],-u[class|style],#p[id|style|dir|class|align]]",
      "InvalidElements": "font",
      "Commands": [
        {
          "Alias": "ace",
          "Name": "Source code editor",
          "Mode": "Insert"
        },
        {
          "Alias": "removeformat",
          "Name": "Remove format",
          "Mode": "Selection"
        },
        {
          "Alias": "paste",
          "Name": "Paste",
          "Mode": "All"
        },
        {
          "Alias": "customlist",
          "Name": "customlist",
          "Mode": "All"
        }
      ],
      "CustomConfig": {
        "Toolbar": "customlist"
      }
    },
    

    In Umbraco, I have edited the document type > richtexteditor and I can see the "customlist" is available and selected. I have also added an alert("test") within the plugin.min.js in the plugin source code and can confirm the alert does fire (even within the tinymce.PluginManager.add('customlists', (editor, url) => {} call, so the plugin itself is definately loaded.

    Problem however is that the button (or text rather) does not show within the toolbar. I suspect that I need to specify in which toolbar, but the base configuration in the appsettings.json does not have seem to look out for the toolbar property. I have added it to the CustomConfig namespace, but no difference.

    Or, it could be my code, but I tested it in codepen and the Toolbar item does show, so I suspect it's down to the initialization part. Any ideas?

  • Marc Goodson 2157 posts 14434 karma points MVP 9x c-trib
    Oct 29, 2023 @ 20:34
    Marc Goodson
    0

    Hi mauzilla

    Looks like the fun starts here:

    https://github.com/umbraco/Umbraco-CMS/blob/8e609af90168a7c5e088b30193266733269457ec/src/Umbraco.Web.UI.Client/src/common/services/tinymce.service.js#L350

    I have had a similar thing before, but along time ago, tinymce4+Umbraco where my plugin didn't specify an icon, and so didn't appear...?

    If you look at the way Umbraco do the custom Umbraco Plugins for TinyMce

    https://github.com/umbraco/Umbraco-CMS/blob/8e609af90168a7c5e088b30193266733269457ec/src/Umbraco.Web.UI.Client/src/common/services/tinymce.service.js#L629

    You can see

     createMediaPicker: function (editor, callback) {
          editor.ui.registry.addButton('umbmediapicker', {
            icon: 'image',
            tooltip: 'Image Picker',
            stateSelector: 'img[data-udi]',
            onAction: function () {
    

    they specify an icon... ?

    regards

    Marc

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies