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
    Ok, here's a question for the core code gurus. I have an add-on that will have its own system settings. Two of these will be to specify options that are based on folders in the add-on's assets. What I want to do is generate the setting drop-down based on available folders. Users can upload more of these folders to provide more options.

    To be specific, it's the markItUp content editor (not a code editor, it inserts tags for html, wiki, markdown, bbcode, etc). The two options will be for sets (html, bbcode, wiki, etc) and skins. The package will come with one or two of each of these, but more can easily be added from the markItUp downloads page.

    The question is, how can I build a dynamic select drop-down in System Settings from these set and skin folders (assets/components/markitup/skins/ and assets/components/markitup/sets/)?
      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
      • 3749
      • 24,544 Posts
      I could be wrong (and I haven't actually looked at the System Settings grid code), but I suspect that the Setting types are hard-coded into the JavaScript. There's no "list" type for settings and there's no field for possible values in the modx_system_settings table. I've thought of a feature request for a Properties field so they'd work like TVs.

      If I'm right, you'd have to hack the JavaScript for the grid and the Controller code, at the least.

      You might be better off with a plugin to set the value of the System Setting, but I'm not sure what event you'd attach it to (OnManagerLogin?).
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        The which_editor for selecting editors for content and for elements are of the xtype modx_combo_rte, so I know it's possible. I don't know how those are generated, though. They may be hard-coded by the RTE's installer. But it should be possible to have a plugin load the values.
          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
          • 3749
          • 24,544 Posts
          This code is in modext.js and modx.combo.js (along with the other combo types like category and role):

          MODx.combo.RTE = function(config) {
              config = config || {};
              Ext.applyIf(config,{
                  name: 'rte'
                  ,hiddenName: 'rte'
                  ,displayField: 'value'
                  ,valueField: 'value'
                  ,fields: ['value']
                  ,forceSelection: true
                  ,typeAhead: false
                  ,editable: false
                  ,allowBlank: false
                  ,listWidth: 300
                  ,url: MODx.config.connectors_url+'system/rte.php'
              });
              MODx.combo.RTE.superclass.constructor.call(this,config);
          };
          Ext.extend(MODx.combo.RTE,MODx.combo.ComboBox);
          Ext.reg('modx-combo-rte',MODx.combo.RTE);
          


          There may be a way to add custom ones without hacking those files, but that's not being done with which_editor.

          (BTW, it's modx-combo-rte, not modx_combo_rte.)
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Maybe those options should be in the plugin's properties rather than 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
              • 3749
              • 24,544 Posts
              It's a little faster and easier to get and explode() a comma-separated list in a System Setting. OTOH, if they're plugin properties, you wouldn't have to create a new System Setting in a resolver during installation.

              I think I would create the System Setting if you need to get and set them outside of the plugin, but you could do it either way.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                I don't understand. How do you get the list into the System Setting?
                  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
                  • 3749
                  • 24,544 Posts
                  In the plugin. It would check the folders against the current value of the System Setting and adjust it if necessary.
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    OnSiteSettingsRender I would presume. Now it's narrowed down to how to specify the options for the setting in the first place.

                    $MySetting = $modx->newObject('modSystemSetting');
                    $MySetting->set('key', 'markitup.set');
                    $MySetting->set('value', '???');
                    $MySetting->set('xtype', 'modx-combo-rte');
                    $MySetting->set('namespace', 'markitup');
                    $MySetting->set('area', 'Rich-Text Editor');
                     
                    $MySetting->save();
                     
                    // Clear the cache:
                    $cacheRefreshOptions =  array( 'system_settings' => array() );
                    $modx->cacheManager-> refresh($cacheRefreshOptions);
                      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
                      • 3749
                      • 24,544 Posts
                      I presume that code is in your resolver as part of the package install? You definitely don't want to try to create a new System Setting every time OnSiteSettingsRender fires.

                      The plugin itself would use getOption(), then (I guess) scandir() to get the possible settings, compare them with the current value, then use getObject() and the set(), save(), and refresh() code above if they don't match.
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting