This plugin creates a folder named with the id of the document in the files folder, then creates a folder named images inside.
In this example it will only happen when the template has an id of 42 and the documents parent has an id of 29 and either folder doesn’t already exist, it is triggered when you save a document.
The "OnDocFormSave" System Event should be checked.
Adjust folders, folder paths, template & parent as needed.
<?php // remove this line, it's just for syntax highlighting
$e = &$modx->Event;
$docid = $e->params['id'];
$dir = $modx->config['rb_base_dir']."files/".$docid;
$images_dir = $modx->config['rb_base_dir']."files/".$docid."/images";
$folder_permissions = octdec($modx->config['new_folder_permissions']);
function mkdirs($strPath, $mode){ // recursive mkdir function
if (is_dir($strPath)) return true;
$pStrPath = dirname($strPath);
if (!mkdirs($pStrPath, $mode)) return false;
return @mkdir($strPath);
}
switch ($e->name) {
case "OnDocFormSave":
if($_REQUEST['template'] == 42 && $_REQUEST['parent'] == 29)
{
if(!file_exists( $dir )){
$old_umask = umask(0);
mkdirs($dir,$folder_permissions);
umask($old_umask);
$sub_umask = umask(0);
mkdirs($images_dir,$folder_permissions);
umask($sub_umask);
}
}
break;
default: "";
return;
}