I hope I understand your question / scenario right, but this could work:
create a listbox TV (in your case the one that should show the resources) and put in:
@EVAL return $modx->runSnippet('setTaggedResourcesList', array('valuetv'=>23, 'searchtv' => 22));
then create a snippet with the following code and call it the same name you set above in the @EVAL statement (e.g. "setTaggedResourcesList")
// this is the array of input values that we will return at the end (imploded)
$inputvalues = array(
'(Please choose)==',
);
// now we get all TemplateVariableResource Objects that exist for the categories TV
// (the one where multiple categories can be specified, e.g. result in something like 9||18||23)
// this is the TV ID you have to specify in the @EVAL snippet call for the property "searchtv"
$tvrobjs = $modx->getCollection('modTemplateVarResource', array('tmplvarid' => $searchtv));
// now we loop over all these Objects and filter out the ones we want
foreach ($tvrobjs as $tvrobj) {
// create an array from a TV Value like 9||18||23 for easier searching
$tags = explode('||', $tvrobj->get('value'));
// if the value of the category tv (which ID you have to specify for the property "valuetv" in the @EVAL call
// is found in a template variable resource object then create a new item for the input values with pagetitle of that
// resource and it's id as value
if (in_array($modx->resource->getTVValue($valuetv), $tags)) {
// fetch the pagetitle for a matching resource
$resobj = $modx->getObject('modResource', array('id' => $tvrobj->get('contentid')));
// build the input value item and add it to the $inputvalues array
$inputvalues[] = $resobj->get('pagetitle') . '==' . $resobj->get('id');
}
}
return implode('||', $inputvalues); // finally implode the whole array to a correct input value options string for the listbox
this is clearly not as elegant as Bobs classExtender, but that's the nice thing about MODX, there are always many ways to accomplish something =)!
this then results in something like what you can see below (not that you have to reload the resource edit form after changing the "valuetv", e.g. switch from Category1 to Category2 (you'll see what I mean when It gets white =D)
In this example there are 3 resources, "Published Child 1 (categories 1,2)", "Published Child 2 (categories 1,3)", "Published Child 3 (categories 1,4)" so when the current resource has selected Category 1, all three resources will be available in the listbox, if you then switch to Category 2, only a single resource is shown as no other has assigned category 2...
PS: sry for the 2 attachments, still can't remove attachments...forum bug...
[ed. note: exside last edited this post 12 years, 4 months ago.]