Had to update my code to deal with moving template variables. It appears that once MODx.moveTV() has moved a TV once, running it again does nothing.
// CB: Add the current rule to the appropriate array
// fieldVisible: Add to the visibilityRules array
// tvMove: Overwrite any previous tvMove rules for that TV
// All others: Just add to the rules array
//if (!empty($r)) $rules[] = $r;
if (!empty($r)) {
if ($rule->get('rule') == 'fieldVisible') {
if (!in_array($r, $visibilityRules)) $visibilityRules[] = $r;
} elseif (($rule->get('rule') == 'tvMove') && (!in_array($r, $rules))) {
$found = false;
$action = substr($r, 0, strpos($r, '],')+2);
for ($i=0; $i < count($rules); $i++) {
if (strpos($rules[$i], $action) !== false) {
$rules[$i] = $r;
$found = true;
}
}
if (!$found) $rules[] = $r;
} else {
if (!in_array($r, $rules)) $rules[] = $r;
}
}
Making TVs visible or not seems to be done somewhere else. If I uncheck the "visible" checkbox on any of the sets, it doesn't change the output of these rules. So unlike the regular resource fields, I can't override it these like I did with the fieldVisible rules. So far I've been able to get around this because I hide the modx-panel-resource-tv tab, so if I don't want a TV showing, I leave it there, and if I do, I move it to the Document tab.
Let me know if I'm breaking any etiquette rules by posting my code updates here. I'm hoping it'll be helpful to someone, and it forces me to quadruple-check everything because I don't want to post stupid code in the forum. ;-) That, and maybe someone will see this and think of better ways to do it.
How could I modify this so it ran in one of the Rendering events? That is an obvious place for it, and I could then copy and hack this function all I wanted, but the original outputs the javascript for these rules right in the function, so I'd have to somehow keep it from running. It's called from render() in modmanagercontroller.class.php and there doesn't seem to be a way to override it.
I guess I could make the entire FC Profile inactive to keep it from running there and then have my function ignore inactive profiles and only pay attention to active/inactive sets? It makes me cringe a bit, although it would work, at least until I actually wanted to make a Profile inactive for real.
Thanks for those other links! Those are going to be a huge help with a couple of other issues I'm having. Another thing I've been having an awful time with in the FC section is dealing with child templates. Knowing more how FC works, I see why, but that will be MUCH easier to deal with using a plug-in.
I looked through the bug list (going by title, I think a LOT of those bugs are related to the priority issues I'm attempting to "fix" here), but I found one with a link that seems to indicate this priority ordering has been added:
https://github.com/modxcms/revolution/commit/ca1d09775114baa05c28a2c4b7bfea62fc36014b
I see the rank field in the modx_actiondom table, and the original code did order the rules using that rank, but the ranking isn't per set, it seems to be per rule, and I can't tell what's setting it. Have I missed something in the interface or is that for future use?