I'm trying to change the parent of a resource based on a value in a tv. I've got this plugin so far:
<?php
/* only for update mode */
if($mode == modSystemEvent::MODE_NEW) { return; }
/* only for resources with parent 11 */
if ($resource->get('parent') == 11) {
$parentFromTv = $resource->getTVValue('new_parent');
/* if a value is set */
if ( ($parentFromTv != '') && ($parentFromTv != '-') ) {
$resource->set('parent', $parentFromTv);
$resource->save();
}
}
return;
I've tried different system events. It's not working on OnDocFormSave. The parent stays '11'.
On OnDocFormRender it does change the parent, but only if the tv 'new_parent' is set, the resource saved and the page manually reloaded. This is not useful for my client.
I must be doing something wrong! It should be possible to change the parent, wouldn't it?
Or maybe I need to refresh the manager page, or send the user to another url after the save. I don't know how to do this. Using sendRedirect is not working for me.
Thanks for any help!