function themekey_taxonomy_tid2tid_and_parents in ThemeKey 7.2
Same name and namespace in other branches
- 6.4 modules/themekey.taxonomy.inc \themekey_taxonomy_tid2tid_and_parents()
- 6.2 modules/themekey.taxonomy.inc \themekey_taxonomy_tid2tid_and_parents()
- 6.3 modules/themekey.taxonomy.inc \themekey_taxonomy_tid2tid_and_parents()
- 7.3 modules/themekey.taxonomy.inc \themekey_taxonomy_tid2tid_and_parents()
- 7 modules/themekey.taxonomy.inc \themekey_taxonomy_tid2tid_and_parents()
ThemeKey mapping function to set a ThemeKey property's value (destination) with the aid of another ThemeKey property (source).
src: taxonomy:tid dst: taxonomy:tid_and_parents
Parameters
$tids: array of taxonomy term ids or a single term id
Return value
array of taxonomy term ids or NULL if no value could be mapped
1 string reference to 'themekey_taxonomy_tid2tid_and_parents'
- themekey_taxonomy_themekey_properties in modules/
themekey.taxonomy.inc - Implements hook_themekey_properties().
File
- modules/
themekey.taxonomy.inc, line 162 - Provides some taxonomy stuff as ThemeKey properties.
Code
function themekey_taxonomy_tid2tid_and_parents($tids) {
/* It might be a bit confusing why the callback for 'taxonomy:tid_and_childs' is
* called themekey_taxonomy_tid2tid_and_parents() and detects the parents for a
* given tid. But it's correct to invert the logic here.
* Example:
* Term 17 has a child 27. The ThemeKey rule is "taxonomy:tid_and_childs = 17".
* So if curent tid is 27, this callback function has to return it's parent 17
* to cause a match in the rule engine.
*/
$tids = is_array($tids) ? $tids : array(
$tids,
);
$parents = array();
foreach ($tids as $tid) {
// note that taxonomy_get_parents_all() returns the term itself
$parent_terms = taxonomy_get_parents_all($tid);
foreach ($parent_terms as $parent_term) {
$parents[] = $parent_term->tid;
}
}
return count($parents) ? array_unique($parents) : NULL;
}