function tvi_get_term_info in Taxonomy Views Integrator 7
Same name and namespace in other branches
- 6 tvi.module \tvi_get_term_info()
Return different data sets for a specified term id.
This function will try to get the term settings, then its ancestors settings, then its vocabulary settings then the default global settings if needed.
Parameters
int $tid: The term tid.
string $type: The kind of data we want.
Return value
null|object The data we asked for.
1 call to tvi_get_term_info()
- tvi_get_view_info in ./
tvi.module - Return information about the arguments given to the taxonomy term callback.
File
- ./
tvi.module, line 345 - Allow to define views to be used instead of default drupal behavior on taxonomy terms pages.
Code
function tvi_get_term_info($tid, $type = TVI_DATATYPE_VIEW) {
static $term_info = array();
if (!array_key_exists($tid, $term_info)) {
$term = taxonomy_term_load($tid);
// Return nothing when term is empty.
if (!$term) {
return NULL;
}
// Try using term and vocabulary overrides.
tvi_include('query');
$settings = tvi_load_settings($term->tid, TVI_TYPE_TERM, FALSE);
// If the term has no settings, search for parent terms' ones.
if (!$settings || empty($settings->status)) {
// Get all the term's ancestors.
$parents = taxonomy_get_parents_all($term->tid);
// Remove the current term from the array.
array_shift($parents);
// While the settings are not set, not active or not inheritables.
while (($current = array_shift($parents)) && (!$settings || empty($settings->status) || empty($settings->inherit))) {
$settings = tvi_load_settings($current->tid, TVI_TYPE_TERM, FALSE);
}
// Avoids the case where no parent of the term are inheritables.
if (empty($settings->inherit)) {
$settings = FALSE;
}
}
// If the term and its parents have no settings, take the vocabulary's one.
if (!$settings || empty($settings->status)) {
$settings = tvi_load_settings($term->vid, TVI_TYPE_VOCAB, FALSE);
}
// If the vocabulary have no settings, take the global settings.
if (!$settings || empty($settings->status)) {
$settings = tvi_load_settings('default', TVI_TYPE_ALL, FALSE);
}
$term_info[$tid] = array(
'term' => $term,
'settings' => $settings,
);
if (isset($settings->view)) {
$term_info[$tid]['view'] = $settings->view;
}
}
switch ($type) {
case TVI_DATATYPE_ALL:
return (object) $term_info[$tid];
case TVI_DATATYPE_TERM:
return $term_info[$tid]['term'];
case TVI_DATATYPE_VIEW:
return $term_info[$tid]['view'];
case TVI_DATATYPE_SETTINGS:
return $term_info[$tid]['settings'];
}
return NULL;
}