Hi folks,
After several attempts and a lot of endeavour, I’ve been able to achieve what I was looking for.
feature:
Link two TV to make the second display values according the choice made for the first one
In my case, people choose beetwen: vegetables||fruits||meal||etc
if TV1==fruits ==> TV2:apple||pear||etc
Here is the solution:
The main issue is to get the same result in the back and the front.
The only way (according my skills) to detect is to check if QEditor is active or not.
My first attempt was to get global values made by QE plugins but I didn’t succeed
But modx is so great that you always have a way to get what you want.
The solution is to create a snippet which will be called from the TV and who shares parameters with QE module based on dependencies
In that case we will share $show_manager_link;
so if show_manager_link is true we are on the front.
SO let’s go:
STEP 1 create your 2 TV
TV1 (select single) = input options value : @SELECT name, id FROM ma_table ORDER by name ASC;
TV2 (multiple select) = input options value : @EVAL return $modx->runSnippet(’createListOptions’);
STEP 2 create a snippet "createListOptions"
ADD this snippet to QE dependencies.
ADD QE to the snippet dependencies (tab configuration)
$value="Select first TV1==";
$qeV = $show_manager_link;
$pageID = ( $qeV == 1) ? $_REQUEST[’doc’] : $modx->getDocumentIdentifier(’id’);
$pageID = ( $_REQUEST[’doc’]) ? $_REQUEST[’doc’] : $modx->getDocumentIdentifier(’id’);
if(!empty($pageID)){
$templateTest = $modx->getTemplateVar(’templateTest’,’*’, $pageID);
if(strlen($templateTest[’value’])>0){
$sql= "SELECT aliment, idaliment FROM modx_aliments WHERE groupe=".$templateTest[’value’]." ORDER by aliment ASC";
$elt="";
$rs = $modx->db->query($sql);
while($myvalues = $modx->db->getRow($rs)) {
$elt .= $myvalues[’aliment’]."==".$myvalues[’idaliment’]."||";
}
$value = substr($elt,0,-2);
}
}
return $value;
:-)
The behaviour is a bit chaootic for now, sometimes the value are not shown in backend , so still investigating.
EDIT : I feel like an idiot
You don’t have to add dependencies
We just have to check $_REQUEST[’doc’] which is the doc id in QE
Now works fine
hope that helps.
PS/ I could not get from my snippet the current id with $modx->documentIdentifier or $modx->documentObject[’id’]