Skip to content

Instantly share code, notes, and snippets.

@alanpich
Last active December 18, 2015 00:49
Show Gist options
  • Save alanpich/5699696 to your computer and use it in GitHub Desktop.
Save alanpich/5699696 to your computer and use it in GitHub Desktop.
Amending ModxCampaignMonitor extra to allow MCM.combo.resource to only show resources that are direct children on a parent resource
<?php
/** core/components/mcm/processors/mgr/resource/getchildlist.class.php */
/**
* Create this file to allow filtering of resources by a parent ID
*
* @param int $parentId
* @return array Array of modResource child elements
*
*/
if(!class_exists('modObjectGetListProcessor')){
include MODX_CORE_PATH.'model/modx/processors/resource/getlist.class.php';
}
class MCMResourceGetChildListProcessor extends modObjectGetListProcessor {
/**
* Amend the xPDO query to allow specifying a 'parent' attribute
*/
public function prepareQueryBeforeCount(xPDOQuery $c) {
$parent = (int)$this->getProperty('parent',false);
if($parent !== false){
$c->where(array('parent') => $parent));
}
return $c;
}
};
return 'MCMResourceGetChildListProcessor';
/** assets/components/mcm/mgr/js/mcm.combo.resource.js **/
MCM.combo.Resource = function(config){
config = config || {};
Ext.applyIf(config,{
id: 'mcm-combo-resource'
,name: 'resourceID'
,hiddenName: 'resourceID'
,displayField: 'pagetitle'
,valueField: 'id'
,mode: 'remote'
,fields: ['id','pagetitle']
,forceSelection: true
,editable: false
,enableKeyEvents: true
,pageSize: 20
,url: MCM_CONNECTORS+'connector.php' /** CHANGE THIS LINE TO POINT TO DIFFERENT CONNECTOR**/
,baseParams: {
action: 'getChildList' /** CHANGE THIS LINE TO USE THE NEW PROCESSOR CREATED ABOVE **/
,showNone: true
}
});
MCM.combo.Resource.superclass.constructor.call(this, config);
};
Ext.extend(MCM.combo.Resource,MODx.combo.ComboBox);
Ext.reg('mcm-combo-resource',MCM.combo.Resource);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment