In it’s current form, MODx only supports three document types (2, really). Folders, documents (type in both cases is document) and a weblink (reference). And most of the time, that enough. Though, for a client of mine, I wanted to add a photo gallery to the document tree so they didn’t have to fiddle around in the Module section to start the module (that’s alot less intuitive as far as I can tell).
And, as far as I could see, MODx didn’t support that out of the box. (Well, alot has been done to make it easy, but here are the finishing touches). Note: the modifications were origionally done against the 0.9.1 release, but the line numbers below resemble the 0.9.2 (and 0.9.2.1)
manager/actions/dynamic/mutate_content.dynamic.action.php
LINE 700
REPLACE
<?php if($content['type']!="reference" && $_REQUEST['a']!=72) { ?>
WITH:
<?php if($content['type']=="document" && $_REQUEST['a']!=72) { ?> // there are some more !="reference" things around, but only this one has to be changed (as far as I can tell)
LINE 742
REPLACE:
<input type="hidden" name="type" value="reference" />
WITH:
<input type="hidden" name="type" value="<?php echo $content['type']?>" />
## Below is optional, and only needed if you want your custom document to display above the Access Permissions block, which will usually be the case
LINE 1029
ADD:
// invoke OnDocFormRender event
$evtOut = $modx->invokeEvent("OnDocFormRender",array("id" => $id));
if(is_array($evtOut)) echo implode("",$evtOut);
LINE 1104
REMOVE:
<?php
// invoke OnDocFormRender event
$evtOut = $modx->invokeEvent("OnDocFormRender",array("id" => $id));
if(is_array($evtOut)) echo implode("",$evtOut);
?>
That’s all that is needed to change to the core, though it still doesn’t do much... (Nothing different at least

). Next, we’ll need to add two menu items (i’d love to be able to do that dynamically).
File: /manager/frames/l4mnu.php
LINE 80:
ADD
<li><a onclick="this.blur();" href="index.php?a=85&cft" target="main">My new custom folder type</a></li>
<li><a onclick="this.blur();" href="index.php?a=72&cdt" target="main">My new custom document type</a></li>
For "folders" (eg, a gallery or a shopping cart administration) the href in the link should be index.php?a=85&<a name for your type>. (You’ll see why <a name for your type> is needed soon). And for documents it should be index.php?a=72&<another name>. (Note, those names should be different!).
There is no limitation to the number of custom documents and folders

.
Now, the only thing to do is, write a plugin to handle your document. This is the bare minimum to get this to work:
if(!function_exists('Find_type_slow')){
function Find_type_slow($id){
if($id == '') return false;
$query = "SELECT type FROM " . $GLOBALS['modx']->getFullTableName('site_content') . ' WHERE id=' . $id;
return $GLOBALS['modx']->db->getValue($GLOBALS['modx']->db->query($query));
}
}
$e =& $modx->Event;
$isFolder = isset($_REQUEST['cft']) || $content['type'] == 'my type of folder' || Find_type_slow($id) == 'my type of folder';
if($isFolder){
if($e->name == 'OnDocFormRender'){
$e->output('<p>The form for createing and editing your type</p>');
$e->output('<input type="hidden" name="cft" value="">'); // name should be the same as the $_REQUEST parameter we're checking above!
}elseif($e->name == 'OnBeforeDocFormSave'){
if($mode == 'new'){
// Insert your new folder in the database.
// Note: you don't have to do the General settings dialog, MODx does that for you. You only need to save YOUR document to the database
}else{
// Update your new folder. Same note as above applies
}
$GLOBALS['type'] = 'my type of folder';
$GLOBALS['isfolder'] = true; // Set to false if you used id=72
}elseif($e->name == 'OnDocFormDelete'){
// Database query for deleting your document
}
}
Lastly, configure the plugin to handle the OnDocFormDelete, OnBeforeDocFormSave, OnDocFormRender events (more events doesn’t hurt, but these are the only events we need).
As a final note, there is no OnDocTreePrune (or something) event, so you’ll have to delete your type completely.
Hope I’ve helped at least someone with this!
Edit: forgot one thing!
If saving the document doesn’t work for some reason (or any other event), this code could be helpfull!
$e->alert("<strong>Warning:</strong><br>This cannot be saved!");
$modx->manager->saveFormValues(72);
$modx->sendRedirect('index.php?a=72&pic');
exit;