We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • You can add a tab to the left of any tabpanel.
    You will have to find the container component beforehand with a code like the following examples:

    // Add a tab at last position - http://docs.sencha.com/extjs/3.4.0/#!/api/Ext.Container-method-add
    Ext.getCmp("modx-resource-tabs").add('your-xtype');
    
    // Add a a tab at the specified position - http://docs.sencha.com/extjs/3.4.0/#!/api/Ext.Container-method-insert
    Ext.getCmp("modx-resource-tabs").insert(0, 'your-xtype');
    
    • That might work in theory, but in practice I still can't make it work. I get the error that "Ext.getCmp is not defined" (for CRC's)... and loading ext-base.js and ext-all.js doesn't seem to make that function defined.
      • For CRC you can't refer to 'modx-resource-tabs' which is the id used for the resources panel.
        Use you own defined id.

        See example here : https://github.com/lossendae/BigBrother/blob/master/assets/components/bigbrother/mgr/cmp/container.js#L12
        and line 63 for example usage.
        • Thanks for the links. Hmm... modx-resource-tabs is defined when creating/editing custom resource types (CRC's). I see it when I inspect the HTML in Firebug. I still don't understand why Ext.getCmp is not in scope for CRC's. Oiy, this is really killing me. I'm willing to pay to get a couple things here worked out here -- message me if you're able/willing to fix up a couple things.
            • Francesco Mussoni | MODX Ambassador | Skype: solidusite2 | Email: [email protected]
            • Yeah, that example is very similar to what I'm trying to do -- did you ever figure out how to add additional fields to the panel?
              • omg sorry, I've wrong post about it.
                I will make a tutorial about it, btw you can find some guideline here:
                http://forums.modx.com/thread/86374/custom-resource-class-with-related-data-question-s#dis-post-478635

                  Francesco Mussoni | MODX Ambassador | Skype: solidusite2 | Email: [email protected]
                • This issue keeps bobbing up like a turd that won't flush (excuse the imagery, but too much time with Ext JS will do that to a man).

                  Here's the simplest way I've found to do add custom tabs to MODX resources and filling them with custom HTML:

                  Add a Custom Tab to the Right of Existing Tabs

                  1. Create a plugin that fires on the OnDocFormPrerender event.
                  2. In the plugin, use code like the following:

                  <?php
                  switch ($modx->event->name) {
                      // Add a custom tab to the MODX create/edit resource pages
                      case 'OnDocFormPrerender':
                          $custom_html = 'Your custom HTML, e.g. from a model function or API lookup etc.';
                          $modx->regClientStartupHTMLBlock('<script type="text/javascript">
                              MODx.on("ready",function() {
                                  MODx.addTab("modx-resource-tabs",{
                                      title: "My Custom Tab",
                                      id: "custom-resource-tab",
                                      width: "95%",
                                      html: '.json_encode(utf8_encode("$custom_html")).'
                                  });
                              });                
                          </script>');
                  }


                  This is trickier if you need to execute Javascript on the included HTML because the "on ready" event will have already fired. One workaround I've found for this is to use Ext JS's "autoLoad" parameter and set the "scripts" attribute to true (if that is false, all the JS on the example.html page will be ignored):

                  MODx.addTab("modx-resource-tabs",{
                      title: "My Custom Tab",
                      id: "custom-resource-tab",
                      width: "95%",
                      autoLoad: {
                              url: "/example.html",
                              scripts : true
                          }
                  });


                  We can take advantage of the addTab() convenience function.

                  Add a Custom Tab to the Left of Existing Tabs

                  As above, but adjust the plugin code so it injects some javascript

                  <?php
                  switch ($modx->event->name) {
                      // Add a custom tab to the MODX create/edit resource pages
                      case 'OnDocFormPrerender':
                          $custom_html = 'Your custom HTML, e.g. from a model function or API lookup etc.';
                          $modx->regClientStartupHTMLBlock('<script type="text/javascript">
                              MODx.on("ready",function() {
                                  	Ext.getCmp("modx-resource-tabs").insert(0, {
                                              title: "Custom Tab",
                                              id: "custom-resource-tab",
                                              width: "95%",
                                              html: '.json_encode(utf8_encode("$custom_html")).'
                                  	});
                              });                
                          </script>');
                  
                  }


                  In the second example, we can't take advantage of the "addTab" function, so instead we use the "insert" function and we specify an index of 0 to indicate the first spot in the array (i.e. the left-most spot).

                  When you need to use a PHP-generated string inside Javascript, there are two subtle headaches lurking there that the above solution avoids:

                  1. Double-quote the string. This isn't our first day at programming school, we have to do this to *force* the output to be a string and not an object because json_encoding an object will end up as some sort of {} variant and it will not populate our tab. Some functions may return objects that will not behave as strings until you trigger __toString() e.g. via concatenation or as I did here, by double-quoting the string.

                  2. Use utf_encode() before you encode to JSON. This will ensure that your solution works even if you have special characters in it.

                  Both solutions take advantage of Ext JS's "html:" attribute, which is a good way to inject 100% custom HTML into the existing MODX forms. It bypasses all the insanity of formatting and debugging hell that is the overly complex mess of working Ext JS. My conclusions of it are damning so my goal with any MODX manager customizations are to get my code into the manager with the least amount of interaction with Ext JS as possible. I want to punch Ext JS right in the Angular.js... [ed. note: Everettg_99 last edited this post 9 years, 10 months ago.]
                  • Actually it's quite easy to add a tab using Form Customization. What doesn't appear to be so easy is positioning it where you want it. [ed. note: sottwell last edited this post 9 years, 11 months ago.]
                      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
                    • I think adding a tab via Form Customization would allow you to use the GUI to dynamically set user permissions and limit access to a specific tab. That could be useful. I'm not clear on how to add content to a tab created via FC, but I suspect something like the following would work:
                      var url = 'something.php';
                      Ext.Ajax.request({
                              url: url,
                              params: {},
                              async:false,
                              success: function(response){
                                  console.log("Success: Data received from "+url);
                                  Ext.fly("my_new_tab_id").update(response.responseText);
                              },
                              failure: function(response){
                                  console.error("The request to "+url+" failed.", response);
                              }
                          });