$categories[] = $resource->getTVValue('category'); $categories = implode(',', $resource->getTVValue('category'));
<?php
$eventName = $modx->event->name;
switch($eventName)
{
case 'OnDocFormSave':
//Referrence to the current Resource tv values
$serie = $resource->getTVValue('serie');
//$category = $resource->getTVValue('category');
$categories = explode(',', $resource->getTVValue('category'));
//$parentObject = $modx->getObject('modResource', array('pagetitle' => 'Pool', 'context_key' => $resource->get('context_key') ));
//Should ensure that the user is doesn't create symlinks for anything other than resources in the right folder
if($resource->get('class_key')!='modDocument' || $resource->get('parent')!= 6/*$parentObject->get('id')*/)
{
echo 'Symlinks NOT created, REASON: Resource is either not a modDocument or product not created in folder Pool';
return;
}
if(!empty($serie))
{
$symParentOne = $modx->getObject('modResource',array('pagetitle' => $serie, 'context_key' => $resource->get('context_key') ));
$existingObjOne = $modx->getObject('modResource',array('pagetitle'=>$resource->get('pagetitle'),'parent'=>$symParentOne->get('id'),'context_key' => $resource->get('context_key') ));
if(!empty($existingObjOne))
{
return;
}
else
{
// Create symlink in serie
$fields = array(
'template' => 7, /* ID of desired template */
'content_type' => 1, /* don't change this */
'class_key' => 'modSymLink',
'context_key' => $resource->get('context_key'),
'parent' => $symParentOne->get('id'), /* id of desired parent */
'richtext' => 1,
'pagetitle' => $resource->get('pagetitle'),
'alias' => $resource->get('pagetitle'),
'hidemenu' => 0,
'published' => 1,
'searchable' => 0,
'cacheable' => 1,
'content' => $resource->get('id') // ID of linked resource
);
$resource = $modx->newObject('modSymlink', $fields);
$resource->save();
}
}
if(!empty($categories))
{
for ( $i = 0; $i <= count($categories); $i++)
{
$symParentTwo = $modx->getObject('modResource',array('pagetitle' => $categories[$i], 'context_key' => $resource->get('context_key') ));
$existingObjTwo = $modx->getObject('modResource',array('pagetitle'=>$resource->get('pagetitle'),'parent'=>$symParentTwo->get('id'),'context_key' => $resource->get('context_key') ));
if(!empty($existingObjTwo))
{
return;
}
else
{
$fields = array(
'template' => 7, /* ID of desired template */
'content_type' => 1, /* don't change this */
'class_key' => 'modSymLink',
'context_key' => $resource->get('context_key'),
'parent' => $symParentTwo->get('id'), /* id of desired parent */
'richtext' => 0,
'pagetitle' => $resource->get('pagetitle'),
'alias' => $resource->get('pagetitle'),
'hidemenu' => 0,
'published' => 1,
'searchable' => 0,
'cacheable' => 1,
'content' => $resource->get('id') // ID of linked resource
);
$resource = $modx->newObject('modSymlink', $fields);
$resource->save();
}
}
}
break;
case 'OnDocFormDelete':
//Referrence to the current Resource, get the name of the current resource for removing of symlinks
//$parentObject = $modx->getObject('modResource', array('pagetitle' => 'Pool', 'context_key' => $resource->get('context_key') ));
//Should ensure that the user is doesn't delete symlinks for anything other than resources in the right folder
if($resource->get('class_key')!='modDocument'|| $resource->get('parent')!= 6/*$parentObject->get('id')*/)
{
return;
}
$symlinks = $modx->getCollection('modSymlink',array('pagetitle'=>$resource->get('pagetitle')));
if(!empty($symlinks))
{
$modx->removeCollection('modSymlink',array('pagetitle'=>$resource->get('pagetitle')));
}
break;
}
$chunk = $modx->getObject('modChunk', array('name'=>'debug'));
/* Put any debugging information in the string, $s */
$ids = $modx->getParentIds(58); /* example function */
$s = 'Debug output' . "\n\n";
$s .= print_r($ids,true); /* example debug output */
$chunk->setContent($s);
$chunk->save();

<?php
/* Do this after creating the Symlink, saving it, and getting its ID. */
/* $resource is the resource object you're creating the Symlink for. */
/* $symlinkId is the ID of the Symlink you've just created. */
/* Get the ID of the resource (if you don't have it already) */
$resourceId = $resource->get('id');
/* get the TV's value for that resource */
$tv = $modx->getObject('modTemplateVar', array( 'name' => 'MyTv'));
$tvId = $tv->get('id');
$tvValue = $tv->getValue($resourceId);
/* create the new templateVarResource object for the symlink
to hold the duplicate value of the TV from the resource
*/
$fields = array();
$fields['tmplvarid'] = $tvId;
$fields['contentid'] = $symlinkId;
$tvt = $modx->newObject('modTemplateVarResource', $fields);
/* duplicate the value from the resource in the Symlink */
$tvt->set('value', $tvValue);
$tvt->save();
<?php
$tvId = 8;
$resourceId = $resource->get('id');
$tv = $modx->getObject('modTemplateVar', $tvId);
$tvValue = $tv->getValue($resourceId);
$fields = array();
$fields['tmplvarid'] = $tvId;
$fields['contentid'] = $symlinkId;
$tvt = $modx->newObject('modTemplateVarResource', $fields);
$tvt->set('value', $tvValue);
$tvt->save();
<?php
$eventName = $modx->event->name;
switch($eventName)
{
case 'OnDocFormSave':
//Referrence to the current Resource tv values
$idx = $resource->get('id');
$serie = $resource->getTVValue('serie');
//$category = $resource->getTVValue('category');
$categories = explode(',', $resource->getTVValue('category'));
//$parentObject = $modx->getObject('modResource', array('pagetitle' => 'Pool', 'context_key' => $resource->get('context_key') ));
//Should ensure that the user is doesn't create symlinks for anything other than resources in the right folder
if($resource->get('class_key')!='modDocument' || $resource->get('parent')!= 6/*$parentObject->get('id')*/)
{
return;
}
if(!empty($serie))
{
$symParentOne = $modx->getObject('modResource',array('pagetitle' => $serie, 'context_key' => $resource->get('context_key') ));
if(empty($symParentOne))
{
return;
}
else
{
$existingObjOne = $modx->getObject('modResource',array('pagetitle'=>$resource->get('pagetitle'),'parent'=>$symParentOne->get('id'),'context_key' => $resource->get('context_key') ));
if(!empty($existingObjOne))
{
return;
}
else
{
// Create symlink in serie
$fields = array(
'template' => 7, /* ID of desired template */
'content_type' => 1, /* don't change this */
'class_key' => 'modSymLink',
'context_key' => $resource->get('context_key'),
'parent' => $symParentOne->get('id'), /* id of desired parent */
'richtext' => 1,
'pagetitle' => $resource->get('pagetitle'),
'alias' => $resource->get('pagetitle'),
'hidemenu' => 0,
'published' => 1,
'searchable' => 0,
'cacheable' => 1,
'content' => $idx // ID of linked resource
);
$resource = $modx->newObject('modSymlink', $fields);
$resource->save();
//obtain the id of the symlink just created
$symId = $resource->get('id');
}
}
}
if(!empty($categories))
{
for ( $i = 0; $i <= count($categories); $i++)
{
$symParentTwo = $modx->getObject('modResource',array('pagetitle' => $categories[$i], 'context_key' => $resource->get('context_key') ));
if(empty($symParentTwo))
{
return;
}
else
{
$existingObjTwo = $modx->getObject('modResource',array('pagetitle'=>$resource->get('pagetitle'),'parent'=>$symParentTwo->get('id'),'context_key' => $resource->get('context_key') ));
if(!empty($existingObjTwo))
{
return;
}
else
{
$fields = array(
'template' => 7, /* ID of desired template */
'content_type' => 1, /* don't change this */
'class_key' => 'modSymLink',
'context_key' => $resource->get('context_key'),
'parent' => $symParentTwo->get('id'), /* id of desired parent */
'richtext' => 0,
'pagetitle' => $resource->get('pagetitle'),
'alias' => $resource->get('pagetitle'),
'hidemenu' => 0,
'published' => 1,
'searchable' => 0,
'cacheable' => 1,
'content' => $idx // ID of linked resource
);
$resource = $modx->newObject('modSymlink', $fields);
$resource->save();
}
}
}
}
//Fill in symLinks TVs, basically all of them, but only for the symlink within serie
$tvArray = array(3,4,5,6,7,39); // The TV ids I want to dublicate
for ($j=0; $j<=count($tvArray); $j++)
{
if(empty($symId))
{
return;
}
else
{
//locate the template variable from the array
$tv = $modx->getObject('modTemplateVar', $tvArray[$j]);
//now get the value of the template variable from our main resource
$tvValue = $tv->getValue($idx);
//continue as long as the value isn't empty
if(!empty($tvValue))
{
//setup the criteria for the new tempate variable
$fields = array();
$fields['tmplvarid'] = $tvArray[$j];
$fields['contentid'] = $symId;
$fields['value'] = $tvValue;
$tvt = $modx->newObject('modTemplateVarResource', $fields);
$tvt->save();
}
else
{
return;
}
}
}
break;
case 'OnDocFormDelete':
//Referrence to the current Resource, get the name of the current resource for removing of symlinks
//$parentObject = $modx->getObject('modResource', array('pagetitle' => 'Pool', 'context_key' => $resource->get('context_key') ));
//Should ensure that the user is doesn't delete symlinks for anything other than resources in the right folder
if($resource->get('class_key')!='modDocument'|| $resource->get('parent')!= 6/*$parentObject->get('id')*/)
{
return;
}
$symlinks = $modx->getCollection('modSymlink',array('pagetitle'=>$resource->get('pagetitle')));
if(!empty($symlinks))
{
$modx->removeCollection('modSymlink',array('pagetitle'=>$resource->get('pagetitle')));
}
break;
}

Okay i feel I'm so close i can taste it.
I've created a for loop of TVs to be added really only need two of them right now, but I thought that might as well add the others.
The manager hangs while trying to test it and the TVs aren't copied, but I suspect that it is because $symId isn't defined or maybe even my $tvArray anyways here's the code as far;
<!--?php $eventName = $modx--->event->name; switch($eventName) { case 'OnDocFormSave': //Referrence to the current Resource tv values $idx = $resource->get('id'); $serie = $resource->getTVValue('serie'); //$category = $resource->getTVValue('category'); $categories = explode(',', $resource->getTVValue('category')); //$parentObject = $modx->getObject('modResource', array('pagetitle' => 'Pool', 'context_key' => $resource->get('context_key') )); //Should ensure that the user is doesn't create symlinks for anything other than resources in the right folder if($resource->get('class_key')!='modDocument' || $resource->get('parent')!= 6/*$parentObject->get('id')*/) { return; } if(!empty($serie)) { $symParentOne = $modx->getObject('modResource',array('pagetitle' => $serie, 'context_key' => $resource->get('context_key') )); if(empty($symParentOne)) { return; } else { $existingObjOne = $modx->getObject('modResource',array('pagetitle'=>$resource->get('pagetitle'),'parent'=>$symParentOne->get('id'),'context_key' => $resource->get('context_key') )); if(!empty($existingObjOne)) { return; } else { // Create symlink in serie $fields = array( 'template' => 7, /* ID of desired template */ 'content_type' => 1, /* don't change this */ 'class_key' => 'modSymLink', 'context_key' => $resource->get('context_key'), 'parent' => $symParentOne->get('id'), /* id of desired parent */ 'richtext' => 1, 'pagetitle' => $resource->get('pagetitle'), 'alias' => $resource->get('pagetitle'), 'hidemenu' => 0, 'published' => 1, 'searchable' => 0, 'cacheable' => 1, 'content' => $idx // ID of linked resource ); $resource = $modx->newObject('modSymlink', $fields); $resource->save(); //obtain the id of the symlink just created $symId = $resource->get('id'); } } } if(!empty($categories)) { for ( $i = 0; $i <= count($categories); $i++) { $symParentTwo = $modx->getObject('modResource',array('pagetitle' => $categories[$i], 'context_key' => $resource->get('context_key') )); if(empty($symParentTwo)) { return; } else { $existingObjTwo = $modx->getObject('modResource',array('pagetitle'=>$resource->get('pagetitle'),'parent'=>$symParentTwo->get('id'),'context_key' => $resource->get('context_key') )); if(!empty($existingObjTwo)) { return; } else { $fields = array( 'template' => 7, /* ID of desired template */ 'content_type' => 1, /* don't change this */ 'class_key' => 'modSymLink', 'context_key' => $resource->get('context_key'), 'parent' => $symParentTwo->get('id'), /* id of desired parent */ 'richtext' => 0, 'pagetitle' => $resource->get('pagetitle'), 'alias' => $resource->get('pagetitle'), 'hidemenu' => 0, 'published' => 1, 'searchable' => 0, 'cacheable' => 1, 'content' => $idx // ID of linked resource ); $resource = $modx->newObject('modSymlink', $fields); $resource->save(); } } } } //Fill in symLinks TVs, basically all of them, but only for the symlink within serie $tvArray = array(3,4,5,6,7,39); // The TV ids I want to dublicate for ($j=0; $j<=count($tvArray); $j++) { if(empty($symId)) { return; } else { //locate the template variable from the array $tv = $modx->getObject('modTemplateVar', $tvArray[$j]); //now get the value of the template variable from our main resource $tvValue = $tv->getValue($idx); //continue as long as the value isn't empty if(!empty($tvValue)) { //setup the criteria for the new tempate variable $fields = array(); $fields['tmplvarid'] = $tvArray[$j]; $fields['contentid'] = $symId; $fields['value'] = $tvValue; $tvt = $modx->newObject('modTemplateVarResource', $fields); $tvt->save(); } else { return; } } } break; case 'OnDocFormDelete': //Referrence to the current Resource, get the name of the current resource for removing of symlinks //$parentObject = $modx->getObject('modResource', array('pagetitle' => 'Pool', 'context_key' => $resource->get('context_key') )); //Should ensure that the user is doesn't delete symlinks for anything other than resources in the right folder if($resource->get('class_key')!='modDocument'|| $resource->get('parent')!= 6/*$parentObject->get('id')*/) { return; } $symlinks = $modx->getCollection('modSymlink',array('pagetitle'=>$resource->get('pagetitle'))); if(!empty($symlinks)) { $modx->removeCollection('modSymlink',array('pagetitle'=>$resource->get('pagetitle'))); } break; }
In addition I've moved $tvt->set('value', $tvValue); inside the fields array, but IMO that shouldn't be the reason for the hang.
Anyways I'm looking forward to hearing from you guys
Best regards
Moonkin