function _hs_taxonomy_token_termpath_for_vid in Hierarchical Select 7.3
Same name and namespace in other branches
- 5.3 modules/hs_taxonomy.module \_hs_taxonomy_token_termpath_for_vid()
- 6.3 modules/hs_taxonomy.module \_hs_taxonomy_token_termpath_for_vid()
Helper function for hs_taxonomy_token_values().
File
- modules/
hs_taxonomy.module, line 1029 - Implementation of the Hierarchical Select API for the Taxonomy module.
Code
function _hs_taxonomy_token_termpath_for_vid($selection, $vid) {
$terms = array();
$selection = is_array($selection) ? $selection : array(
$selection,
);
// Generate the part we'll need of the Hierarchical Select configuration.
$config = array(
'module' => 'hs_taxonomy',
'save_lineage' => 1,
'params' => array(
'vid' => $vid,
'exclude_tid' => NULL,
'root_term' => NULL,
),
);
// Validate all items in the selection, if any.
if (!empty($selection)) {
foreach ($selection as $key => $item) {
$valid = module_invoke($config['module'], 'hierarchical_select_valid_item', $selection[$key], $config['params']);
if (!$valid) {
unset($selection[$key]);
}
}
}
// Generate a dropbox out of the selection. This will automatically
// calculate all lineages for us.
// If the selection is empty, then the tokens will be as well.
if (!empty($selection)) {
$dropbox = _hierarchical_select_dropbox_generate($config, $selection);
// If no lineages could be generated, these tokens cannot be created!
if (empty($dropbox->lineages)) {
return $terms;
}
// We pick the first lineage.
$lineage = $dropbox->lineages[0];
// Finally, we build the tokens.
foreach ($lineage as $item) {
$terms[] = $item['label'];
}
}
return $terms;
}