I think OnResourceDelete would be the best choice, but it would be tricky since children of the resource are automatically deleted.
In OnResourceDelete, the following variables are available:
$id (ID of the resource)
$resource (the resource object)
$children (array of child IDs)
OnResourceUndelete is also available, but the $children variable is not available (though the children are restored) and you wouldn't know what value to use for the TV.
The cleanup code for onResourceDelete would look something like this (with some added sanity checks):
<?php
$tvId = 12; // Set to the ID of the TV
$tvrs = $modx->getCollection('modTemplateVarResource', array('tmplvarid'=> $tvId));
/* add the resource ID to the children array */
$children[] = $id;
foreach ($tvrs as $tvr) {
if (in_array($tvr->get('value'), $children)) {
$tvr->remove();
}
}
If it's a muli-select TV, things get more complicated.
[ed. note: BobRay last edited this post 15 years, 1 month ago.]