Again what sounds simple sometimes, takes your day. Tried to get some data via MODX processor and bind it to a ExtJS tree.
Main mistakes: I tried to extend modObjectGetListProcessor and not modObjectProcessor, for some reason I could not set the root node to results as other elements allow.
Known this and looking at core/model/modx/processors/security/group/getnodes.class.php make things clear.
So that’s what I came up with.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | /** * Get a list of Tags * * @package modtours * @subpackage processors */ class TagGetNodesProcessor extends modObjectProcessor { public $classKey = 'Tag'; public $languageTopics = array('modtours:default'); public $defaultSortField = 'name'; public $defaultSortDirection = 'ASC'; public $objectType = 'modtours.tag'; /* * Get list by parent */ public function process() { // Get parent ID $parentId = str_replace('n_ug_','', $this->getProperty('id') ); // Get child tags $tagList = $this->getTags($parentId); // Write list $newList = array(); foreach( $tagList as $item ){ // Check if children exist $itemChilds = $this->getTags($item->get('id')); if( !empty($itemChilds) ){ $leaf = false; $type = 'dir'; }else{ $leaf = true; $type = 'file'; } // Write new node item $newList[] = array( 'text' => $item->get('name'), 'name' => $item->get('name'), 'description' => $item->get('description'), 'parentid' => $item->get('id'), 'id' => 'n_ug_0' . $item->get('id'), 'leaf' => $leaf, 'type' => $type, 'cls' => '' ); } return $this->toJSON($newList); } /* * Get results of tags by parent id */ protected function getTags($parentId) { $tagList = $this->modx->getCollection('Tag',array( 'parentid' => $parentId )); return $tagList; } } return 'TagGetNodesProcessor'; |
And then just create your new tree Object
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | modTours.tree.Tags = function(config) { config = config || {}; Ext.applyIf(config,{ title: _('modtours.tags') ,id: 'modtours-tree-tags' ,url: modTours.config.connectorUrl ,action: 'tag/getnodes' ,root_id: '0' ,root_name: _('Tags') ,rootVisible: true ,ddAppendOnly: true ,useDefaultToolbar: true }); modTours.tree.Tags.superclass.constructor.call(this,config); }; Ext.extend(modTours.tree.Tags,MODx.tree.Tree); Ext.reg('modtours-tree-tags',modTours.tree.Tags); |
Which you can use like
1 2 3 4 | ,items: [{ xtype: 'modtours-tree-tags' ,preventRender: true }] |
Hope this helps..



















