function _tac_lite_get_terms in Taxonomy Access Control Lite 7
Same name and namespace in other branches
- 8 tac_lite.module \_tac_lite_get_terms()
- 5 tac_lite.module \_tac_lite_get_terms()
- 6 tac_lite.module \_tac_lite_get_terms()
Gets terms from a node that belong to vocabularies selected for use by tac_lite
Parameters
$node: A node object
Return value
An array of term ids
1 call to _tac_lite_get_terms()
- tac_lite_node_access_records in ./
tac_lite.module - Implements hook_node_access_records().
File
- ./
tac_lite.module, line 509 - Control access to site content based on taxonomy, roles and users.
Code
function _tac_lite_get_terms($node) {
$tids = array();
// Get the vids that tac_lite cares about.
$vids = variable_get('tac_lite_categories', NULL);
if ($vids) {
// Load all terms found in term reference fields.
// This logic should work for all nodes (published or not).
$terms_by_vid = tac_lite_node_get_terms($node);
if (!empty($terms_by_vid)) {
foreach ($vids as $vid) {
if (!empty($terms_by_vid[$vid])) {
foreach ($terms_by_vid[$vid] as $tid => $term) {
$tids[$tid] = $tid;
}
}
}
}
// The logic above should have all terms already, but just in case we use
// the "original" logic below. The taxonomy module stopped writing to the
// taxonomy_index for unpublished nodes, so this works only for published
// nodes.
$query = db_select('taxonomy_index', 'r');
$t_alias = $query
->join('taxonomy_term_data', 't', 'r.tid = t.tid');
$v_alias = $query
->join('taxonomy_vocabulary', 'v', 't.vid = v.vid');
$query
->fields($t_alias);
$query
->condition("r.nid", $node->nid);
$query
->condition("t.vid", $vids, 'IN');
$result = $query
->execute();
foreach ($result as $term) {
if (empty($tids[$term->tid])) {
watchdog('tac_lite', 'Unexpected term id %tid associated with !node. Please report this to !url.', array(
'%tid' => $term->tid,
'!node' => l($node->title, 'node/' . $node->nid),
'!url' => 'https://drupal.org/node/1918272',
), WATCHDOG_DEBUG);
}
$tids[$term->tid] = $term->tid;
}
}
elseif (user_access('administer tac_lite')) {
drupal_set_message(t('tac_lite.module enabled, but not <a href=!admin_url>configured</a>. No tac_lite terms associated with %title.', array(
'!admin_url' => url('admin/config/people/tac_lite'),
'%title' => $node->title,
)));
}
return $tids;
}