zoadie Reply #1, 3 months, 1 week ago
I have an plugin on UserSave event that creates a ResourcesX for every UserX. See details here http://forums.modx.com/thread/74062/onusersave-am-i-doing-it-right-solved#dis-post-411474
Now I want to add to each UserX the setting ('tree_root_id', $resourceXid). I added the following code in the same plugin and it adds the setting but it keeps creating new Resources over and over because it's onUserSave event.
If I remove the last line, doesn't add the setting.
How shall I do it?
Now I want to add to each UserX the setting ('tree_root_id', $resourceXid). I added the following code in the same plugin and it adds the setting but it keeps creating new Resources over and over because it's onUserSave event.
//allowing each user to see only their own resource in the resource tree
$userSettings = $modx->newObject('modUserSetting');
$userSettings->set('key', 'tree_root_id');
$userSettings->set('value', $resource->get('id'));
$userSettings->set('xtype', 'textfield');
$userSettings->set('namespace', 'core');
$userSettings->set('area', 'user');
// use addMany() because settings are the many in a one-to-many relationship from user
$user->addMany($userSettings);
$user->save();
If I remove the last line, doesn't add the setting.
How shall I do it?