We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    I have my custom option widget. I can create a custom System Setting using one of the MODx option widgets. What I can't figure out is how to get my custom option widget into the System Settings. So how does one go about getting a custom option widget recognized by the System Settings manager?
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 4172
      • 5,888 Posts
      If you are talking about the listbox with xtypes for system-settings.
      They are hardcoded:

      https://github.com/modxcms/revolution/blob/develop/manager/assets/modext/widgets/core/modx.grid.settings.js#L433
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 4172
        • 5,888 Posts
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Yes, we know we can't use the New Setting button for this. What we can do is in a resolver programmatically create a setting using a custom option type (like the ones defined in the manager/assets/modext/widgets/core/modx.combo.js) - in fact, I can use a snippet to create a new System Setting using any one of the option widgets defined in that file, and they'll work as expected, even to being already populated. For example, if you specify modx-option-rte you'll get a list of available editors, just like the which_editor setting.

          The trick is in defining our own custom option widget, populating it, then getting it into the System Settings so the user can select the setting option he wants.

          Now, for example, for plugin properties, this is easy. You can select a "list" type, then you'll be given fields to add as many options to the list as you like.

          It's not that simple for System Settings.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 33976 ☆ A M B ☆
            • 571 Posts
            I guess if you want to use a custom xtype on the settings grid, you will have to create a plugin loading your JS file (in which your xtype is defined) when being on the system setting action "page".

            Untested but here is the idea :
            <?php
            /**
             * @var modX $modx
             * @event OnManagerPageBeforeRender
             */
            // Make sure we are on the system setting 'page'
            if (70 == $_GET['a']) {
                /** @var modManagerController $controller */
                $controller = $modx->event->params['controller'];
                $controller->addJavascript('/url/to/your/js/file.js');
            }
            
            return '';
            


            Might be too much work for the "small" benefit.

            Hope this will help smiley
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              onSiteSettingsRender works better. A bit tricky to figure out its syntax. It'll be getting documented eventually, once we figure out exactly what we've done. Even figured out how to add our custom x-types to the New Setting drop-down.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 33976 ☆ A M B ☆
                • 571 Posts
                Might be.
                In that case i fear i don't understand what you are looking for smiley
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  I have a rich text editor (markItUp) to embed. It has options for a number of "sets" (HTML, BBCode, MarkDown, etc), as well as options for skins. I want to have select drop-downs in the System Settings for it so these two things can be selected; it needs to be dynamic because a user can download more sets and skins into specific directories. That's all. Easy enough to do in the plugin's properties, but not so easy in System Settings.
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 33976 ☆ A M B ☆
                    • 571 Posts
                    So, like i said (but this time it's tested ^^)

                    <?php
                    /**
                     * @var modX $modx
                     * @event OnManagerPageBeforeRender
                     */
                    // Make sure we are on the system setting 'page'
                    if (70 == $_GET['a']) {
                        /** @var modManagerController $controller */
                        $controller = $modx->event->params['controller'];
                        // Commented here is the "custom xtype will be hardcoded later (see var demoXtype)
                        //$controller->addJavascript('/url/to/your/js/file.js');
                        $controller->addHtml(
                    '<script type="text/javascript">
                        // This a demo combo, instead use your own with your processor to load your "options"
                        var demoXtype = function(config) {
                            Ext.apply(config, {
                                store: new Ext.data.SimpleStore({
                                    fields: ["data","value"]
                                    ,data: [
                                        ["Displayed", "value"]
                                        ,["Displayed2", "value2"]
                                    ]
                                })
                                ,displayField: "data"
                                ,valueField: "value"
                                ,mode: "local"
                            });
                            demoXtype.superclass.constructor.call(this, config);
                        };
                        Ext.extend(demoXtype, MODx.combo.ComboBox);
                        Ext.reg("demo-xtype", demoXtype);
                    
                        Ext.onReady(function() {
                            Ext.override(MODx.combo.xType, {
                                listeners: {
                                    afterRender: {
                                        fn: function(elem) {
                                            var store = elem.getStore();
                                            // Add your custom xtype(s)
                                            var newXtypes = [
                                                new Ext.data.Record({
                                                    d: "Demo xtype"
                                                    ,v: "demo-xtype"
                                                })
                                                ,new Ext.data.Record({
                                                    d: "Another fake xtype"
                                                    ,v: "textfield"
                                                })
                                            ];
                                            store.add(newXtypes);
                                        }
                                        ,scope: this
                                    }
                                }
                            });
                    });
                    </script>');
                    }
                    
                    return '';
                    


                    I did not play with onSiteSettingsRender since, as far as i understand, it's meant to add some HTML in your setting panel.
                    I also did not took the time to correctly dig on the events, so using afterRender here might not be the best choice (but it does the job).

                    Good luck smiley
                      • 39932
                      • 483 Posts
                      Quote from: romain at May 01, 2013, 05:00 AM

                      I did not play with onSiteSettingsRender since, as far as i understand, it's meant to add some HTML in your setting panel.

                      You are correct. $modx->event->output renders into a new Ext component. However, you may still register CSS and JS via $modx->regClientStartUpScript() and $modx->regClientStartUpCss(). Incidentally, do not put an end script tag in the output. It will break the System Settings screen.

                      Quote from: romain at May 01, 2013, 05:00 AM

                      if (70 == $_GET['a']) {


                      Something to consider: There is no guarantee that the value of 'a' will remain at 70. Should a version update occur that changes the action keys, 'a' will most definitely not be '70'. [ed. note: fuzzicallogic last edited this post 13 years, 5 months ago.]
                        Website: Extended Dialog Development Blog: on Extended Dialog
                        Add-ons: AJAX Revolution, RO.IDEs Editor & Framework (in works) Utilities: Plugin Compatibility List
                        Tutorials: Create Cross-Context Resources, Cross-Context AJAX Login, Template-Based Actions, Remove Extensions from URLs

                        Failure is just another word for saying you didn't want to try. "It can't be done" means "I don't know how".