We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37108
    • 80 Posts
    I have a data point in my CMP that needs a combobox filled with the IDs (value) and titles (label) of a certain container's children. I don't want to use a local data store if I don't need to. On the JS side, within my [cmp].grid.js file, I have the following:
    Flexmail.combo.sourceDocs = function(config){
        config = config || {};
        Ext.applyIf(config,{
            valueField: 'id',
            displayField: 'pagetitle',
            fields: ['id','pagetitle','year','pubname'],
            url: Flexmail.config.connectorUrl,
            baseParams: { action: 'mgr/campaigns/sourcedocsflat' },
            tpl: new Ext.XTemplate('<tpl for="."><div class="x-combo-list-item">{pagetitle} ({id})</div></tpl>')
        });
        Flexmail.combo.sourceDocs.superclass.constructor.call(this,config);
    };
    Ext.extend(Flexmail.combo.sourceDocs,MODx.combo.ComboBox);
    Ext.reg('flexmail-combo-sourcedocs',Flexmail.combo.sourceDocs);
    

    So, that's going to look for a sourcedocsflat file to return values to fill the form field. First question on that: Does sourcedocsflat need to be a class (in sourcedocsflat.class.php) extending on of ModX's classes, or can it be a straight php file (sourcedocsflat.php). On the former, what class would I need to extend to gain access to resource data? In either case, what would the modx object be available as ($this, $this->modx, $modx, something else)?

    This question has been answered by markh. See the first response.

    • discuss.answer
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      Quote from: smg6511v2 at Jan 01, 2013, 07:12 PM

      So, that's going to look for a sourcedocsflat file to return values to fill the form field. First question on that: Does sourcedocsflat need to be a class (in sourcedocsflat.class.php) extending on of ModX's classes, or can it be a straight php file (sourcedocsflat.php). On the former, what class would I need to extend to gain access to resource data? In either case, what would the modx object be available as ($this, $this->modx, $modx, something else)?

      It can be both a class and a straight php file, tho I recommend using a class.

      Could do something like this to get all resources with parent 5.. (untested)
      class SourceDocsFlatGetlistProcessor extends modObjectGetListProcessor {
          public $classKey = 'modResource';
          public $defaultSortField = 'pagetitle';
          public $defaultSortDirection = 'ASC';
      
          /**
           * @param xPDOQuery $c
           * @return xPDOQuery
           */
          public function prepareQueryBeforeCount(xPDOQuery $c) {
              $c->where(array(
                  'parent' => 5,
              ));
              return $c;
          }
      }
      return 'SourceDocsFlatGetlistProcessor';


      When using the class method, make sure to change
              baseParams: { action: 'mgr/campaigns/sourcedocsflat' },

      to
              baseParams: { action: 'mgr/campaigns/sourcedocsflat', combo: true },


      to have the processor return it in the right format.

      Here's a bunch more info on the modObjectGetList processor: https://www.markhamstra.com/modx-blog/2012/04/modobjectgetlistprocessor-class-based-processor/ and the raw API docs: http://api.modx.com/revolution/2.2/db_core_model_modx_modprocessor.class.html#%5CmodObjectGetListProcessor [ed. note: markh last edited this post 13 years, 8 months ago.]
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 37108
        • 80 Posts
        Thanks for the pointers, Mark. FYI one typo in the above solution:
        public function prepareQueryBeforeCount(xPDOQuery $c) {
                $c->where(array(
                    'parent' => 5,
                }
                return $c;
            }


        ... should be ...
        public function prepareQueryBeforeCount(xPDOQuery $c) {
                $c->where(array(
                    'parent' => 5,
                ));
                return $c;
            }


        And, I found the combo: true param to be unnecessary.
          • 18373 ☆ A M B ☆
          • 3,141 Posts
          Cheers, updated the code smiley

          I always thought the combo param was required, but never actually tested that and it's great to know it's not!
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.