Sure ! I don't use an x-type 'modx-tree-directory' but a combobox that display the list of the folders and subfolders ignoring files.
The code of the combo in the create window is
//[...]
fields: [{
xtype: 'picman-combo-folders',
fieldLabel: 'Folder',
name: 'folder',
hiddenName: 'folder',
displayField: 'folder',
valueField:'folder',
anchor: '100%'
}]
//[...]
The Picman.combo.Folders code is:
Picman.combo.Folders = function(config){
config = config || {};
Ext.applyIf(config,{
id: 'picman-combo-folders',
url: Picman.config.connectorUrl,
baseParams: {
action: 'mgr/images/getListFolder'
},
store: new Ext.data.JsonStore({
autoLoad: true,
url: Picman.config.connectorUrl,
baseParams: {
action: 'mgr/images/getListFolder'
},
fields: ['folder']
})
});
Picman.combo.Folders.superclass.constructor.call(this, config);
};
Ext.extend(Picman.combo.Folders,MODx.combo.ComboBox);
Ext.reg('picman-combo-folders',Picman.combo.Folders);
and the processor picmanGetListFolderProcessor code is
<?php
class picmanGetListFolderProcessor extends modProcessor {
public $combo = true;
public function process() {
$assetspath = $this->modx->config['assets_path'];
$dir = $assetspath . 'master/img';
$stack[] = $dir;
while ($stack) {
$thisdir = array_pop($stack);
if ($dircont = scandir($thisdir)) {
$i = 0;
while (isset($dircont[$i])) {
if ($dircont[$i] !== '.' && $dircont[$i] !== '..') {
$current_file = "{$thisdir}/{$dircont[$i]}";
if (is_file($current_file)) {
$path[] = "";
} elseif (is_dir($current_file)) {
$path[] = "{$thisdir}/{$dircont[$i]}";
$stack[] = $current_file;
}
}
$i++;
}
}
}
$lp = count($path);
for ($x = 0; $x < $lp; $x++) {
$suppr = $assetspath . 'master/img/';
$fold = $path[$x];
if ($fold != '') {
$folder = str_replace($suppr, '', $fold);
$myArray[] = $folder;
$listtmp = array('folder' => $folder);
$myArr[] = $listtmp;
}
}
return $this->toJSON($myArr);
}
}
return 'picmanGetListFolderProcessor';
It should be improved with some checks (folder readable/writable ie) but at the moment it fit my immediate needs
Cheers