I usually solve this problem by simply duplicating a resource whose settings I want duplicated instead of creating a new one.
If it were just me, then I'd probably do the same but there will be a few too many fields that may need altering with each duplication. I like to try and make my manager pages as fool-proof as possible for the client.
I decided to go down the plugin route - seemed like the only viable option - but I'm having issues. The intention of the following should be fairly self-explanatory, but it's not working. Not quite sure what I'm doing wrong...
switch ($modx->event->name) {
case 'OnBeforeDocFormRender':
// Creating a new document
if ($mode == modSystemEvent::MODE_NEW) {
// Get parent resource id
$parentid = $modx->resource->get('parent');
// Get parent resource object
$parent = $modx->getObject('modResource',array(
'id' => $parentid
));
// Get parent resource template id
$tpl = $parent->get('template');
// If it's a descendant of the projects folder, make it a project
if ($parentid == 2) {
$resource->set('template','2');
};
// If it's a descendant of a project, make it an event
if ($tpl == 2) {
$resource->set('template','3');
};
};
break;
};
return;
Any clues?
EDIT: I'm aware there's only one case - I'm trying to get it working bit-by-bit.
Also, I'm attempting to set the template when the new document form is created. But I can't find much info about this system event - is it even possible?
[ed. note: chr.s last edited this post 12 years, 5 months ago.]