We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 53312
    • 6 Posts
    modxmeister Reply #1, 7 years ago
    Hi. Recently I started to develop my first plugin and now I have to create custom manager panel for it.
    I've already created the panel (https://docs.modx.com/revolution/2.x/developing-in-modx/advanced-development/custom-manager-pages/custom-manager-pages-in-2.3).
    So next step is to add some ExtJS fields and panels but I can't get what function I should use to add some css and javascript in <head> tag.

    This is a controller class for my new manager panel:
    <?php
    class CustompanelHomeManagerController extends modExtraManagerController {
    
       public function process(array $scriptProperties = array()) {}
    
       public function getPageTitle() {
          return 'This is a custom manager panel';
       }
       public function getTemplateFile() {
          return 'home.tpl';
       }
    }
    


    Could anybody write some exmaple please?
    • If you have a main class for your CMP, that has a version inside and sets the jsUrl and cssUrl, you could use the following code in the controller class:

      class XxxHomeManagerController extends modExtraManagerController
      {
          /** @var Xxx $xxx */
          public $xxx;
      
          public function initialize()
          {
              $corePath = $this->modx->getOption('xxx.core_path', null, $this->modx->getOption('core_path') . 'components/xxx/');
              $this->xxx = $this->modx->getService('xxx', 'Xxx', $corePath . '/model/xxx/', array(
                  'core_path' => $corePath
              ));
          }
      
          public function loadCustomCssJs()
          {
              $jsUrl = $this->xxx->getOption('jsUrl') . 'mgr/';
              $cssUrl = $this->xxx->getOption('cssUrl') . 'mgr/';
      
              $this->addCss($cssUrl . 'xxx.min.css');
              $this->addLastJavascript($jsUrl . 'xxx.min.js?v=v' . $this->xxx->version);
              $this->addHtml('<script type="text/javascript">
              Ext.onReady(function() {
                  Xxx.config = ' . $this->modx->toJSON($this->xxx->options) . ';
                  MODx.load({ xtype: \'xxx-panel-home\'});
              });
              </script>');
          }
      }
      


      There is a lot of example code in my free extras available, i.e. https://github.com/Jako/CustomRequest has a CMP inside.
        • 53312
        • 6 Posts
        modxmeister Reply #3, 7 years ago
        Thank you for reply!
        I just tried to do as shown in your example but something went wrong.

        Then I found solution. It was necessary to add just one function correctly:
        <?php
        class MycmpWelcomeManagerController extends modExtraManagerController {
        
           public function process(array $scriptProperties = array()) {}
        
           public function loadCustomCssJs() {
               $this->addJavascript(MODX_ASSETS_URL.'components/mycmp/js/mgr/mycmp.js');
           }
        
           public function getPageTitle() {
              return 'My Test CMP';
           }
           public function getTemplateFile() {
              return 'welcome.tpl';
           }
        }
        

        There is a plugin sample for education purposes at this link (https://github.com/splittingred/Doodles/tree/2.1). You can also find some info in modx docs about it (https://docs.modx.com/revolution/2.x/case-studies-and-tutorials/developing-an-extra-in-modx-revolution-modx-2.1-and-earlier).