I wrote this today. Copy and paste code into managermanager/functions/fieldvalues.inc.php
//---------------------------------------------------------------------------------
// mm_conditional
// Set Value based on a parent value values from a parent
//---------------------------------------------------------------------------------
function mm_conditional($fields, $value, $parentvalue, $conditional='IS', $roles='', $templates='') {
global $mm_fields, $modx;
$e = &$modx->Event;
// if we've been supplied with a string, convert it into an array
$fields = makeArray($fields);
$output = " // ----------- Conditional -------------- \n";
// if we aren't creating a new document or folder, we don't want to do this
//if (!($modx->manager->action == "85" || $modx->manager->action == "4")) {
// return;
//}
// Are we using this rule?
if (useThisRule($roles, $templates)) {
//$output = " // ----------- Inherit -------------- \n";
// Get the parent info
if (isset($_REQUEST['id'])){
$parentID = $modx->getPageInfo($_REQUEST['id'],0,'parent');
$parentID = $parentID['parent'];
} else {
$parentID = 0;
}
foreach ($fields as $field) {
switch ($field) {
default:
// get some info about the field we are being asked to use
if (isset($mm_fields[$field])) {
$fieldtype = $mm_fields[$field]['fieldtype'];
$fieldname = $mm_fields[$field]['fieldname'];
} else {
break;
}
// Get this field data from the parent
$newArray = $modx->getDocument($parentID, $field);
$newvalue = $newArray[$field];
$output .= "\n// --- $fieldtype ---\n";
if ($conditional == 'IS')
{
$output .= "\n// --- IS: $newvalue == $parentvalue ---\n";
if ($newvalue == $parentvalue)
{
$output .= '$("'.$fieldtype.'[@name='.$fieldname.']").val("' . jsSafe($value) . '");';
}
else
{
$output = '';
}
}
elseif($conditional == 'ISNOT')
{
if ($newvalue != $parentvalue)
{
$output .= '$("'.$fieldtype.'[@name='.$fieldname.']").val("' . jsSafe($value) . '"); ';
}
else
{
$output = '';
}
}
else
{
$output = '';
}
break;
}
$e->output($output . "\n");
}
}
}
Use like:
mm_conditional('template',9,10); // if the parent template is 10, it will change this template to 9. Unfortunately it will not get any of the managermanager attributes for the new template.
or
mm_conditional('pagetitle','This is a sub news document','News'); // if the pagetitle is news, set this pagetitle to 'This is a ...'
I haven’t tested it a lot and it didn’t work out for how I wanted to use it (to automatically set the template of child documents to a different template than the parent...AND get the manager manager attributes for the new template).
Hope this helps someone else.
James