Okay, I’ve come up with a solution, which may not be very pretty but which works. Basically, I’ve written a little snippet to carry out what I want it to do. It’s only useful for this very particular case. People who know the API better or who know PHP better will no doubt be able to come up with something more useful and efficient.
<?php
if(!isset($id)) { //Find current document id.
$id=$modx->documentIdentifier;
}
if($modx->documentObject['isfolder'] == 1) {
if($modx->documentObject['hidemenu'] == 0) { //If the page is a container and it is NOT hidden, then call wayfinder with hidden items still hidden. Otherwise, find parent of document.
return $modx->runSnippet('Wayfinder', array('startId'=>'0', 'level'=>'4', 'hideSubMenus'=>'TRUE', etc));
} else { //Otherwise, make sure this folder will be included later.
$includeId = $id;
}
} else { //If this is not a container, then find the parent of the document (which will be a folder) and check to see if it is hidden. If it is hidden, make sure will be included later.
$parentId = $modx->documentObject['parent'];
$result = $modx->db->query( "SELECT hidemenu FROM modx_site_content WHERE id=$parentId" );
$row = $modx->db->getRow( $result );
if($row['hidemenu'] == 1) { //If hidden, ensure will be displayed.
$includeId = $parentId;
} else { //If not hidden, run wayfinder as normal.
return $modx->runSnippet('Wayfinder', array('startId'=>'0', 'level'=>'4', 'hideSubMenus'=>'TRUE', etc));
}
}
if(isset($includeId)) { //If there we have selected a hidden container, or if we have selected the child of a hidden container, find all hidden documents
$result = $modx->db->query( "SELECT id FROM modx_site_content WHERE hidemenu = 1" );
$excludeIds = '';
while($row = $modx->db->getRow( $result )) { //Cycle through hidden documents, and concatenate them in a comma-delimited string.
if($row['id'] != $includeId) { //Except for the identified container.
$excludeIds .= $row['id'] . ",";
}
}
$excludeIds = substr($excludeIds, 0, -1); // Remove redundent comma from end of list.
//Finally, run wayfinder with hidden documents shown, but with submenus hidden and all other hidden documents excluded.
return $modx->runSnippet('Wayfinder', array('startId'=>'0', 'level'=>'4', 'hideSubMenus'=>'TRUE', 'excludeDocs'=>$excludeIds, etc));
}
?>
Snippets are fun! Sometime I’m going to learn to do them better!