function ctools_term_context in Chaos Tool Suite (ctools) 6
Same name and namespace in other branches
- 7 plugins/arguments/term.inc \ctools_term_context()
Discover if this argument gives us the term we crave.
1 string reference to 'ctools_term_context'
File
- plugins/
arguments/ term.inc, line 28 - Plugin to provide an argument handler for a Taxonomy term
Code
function ctools_term_context($arg = NULL, $conf = NULL, $empty = FALSE) {
// If unset it wants a generic, unfilled context.
if ($empty) {
return ctools_context_create_empty('term');
}
switch ($conf['input_form']) {
case 'tid':
default:
if (!is_numeric($arg)) {
return FALSE;
}
$term = taxonomy_get_term($arg);
break;
case 'term':
$terms = taxonomy_get_term_by_name($arg);
$conf['vids'] = is_array($conf['vids']) ? array_filter($conf['vids']) : NULL;
if (count($terms) > 1 && isset($conf['vids'])) {
foreach ($terms as $potential) {
foreach ($conf['vids'] as $vid => $active) {
if ($active && $potential->vid == $vid) {
$term = $potential;
// break out of the foreaches AND the case
break 3;
}
}
}
}
$term = array_shift($terms);
break;
}
if (empty($term)) {
return NULL;
}
if (!empty($conf['vids']) && array_filter($conf['vids']) && empty($conf['vids'][$term->vid])) {
return NULL;
}
$context = ctools_context_create('term', $term);
$context->original_argument = $arg;
return $context;
}