function _faq_ask_get_terms in FAQ_Ask 7
Get the term id's related to a node or a form posting Returns an array of all term ids of a node if the terms are part of the vocabularies selected for FAQ-Ask. If no terms then an array with a single 0 as term id is returned
Parameters passed as array should be the $form_state['values'] part of a form submission
Parameters
(object|array) $data:
Return value
array of terms ids
1 call to _faq_ask_get_terms()
- faq_ask_node_insert in ./
faq_ask.module - Implementation of hook_node_insert()
File
- ./
faq_ask.module, line 579 - This module is an add-on to the FAQ module that allows users with the 'ask question' permission to create a question which will be queued for an 'expert' to answer.
Code
function _faq_ask_get_terms($data) {
$category = array();
$vocabs = variable_get('faq_ask_vocabularies', 0);
$language = is_object($data) ? $data->language : $data['language'];
if (is_object($data)) {
$data = (array) $data;
}
// Get fields relevant for the faq node and
$fields = field_info_instances('node', 'faq');
foreach ($fields as $name => $properties) {
if (isset($properties['display']['default']['module']) && $properties['display']['default']['module'] != 'taxonomy') {
unset($fields[$name]);
}
}
// Parse through all tagging fields in use
foreach ($fields as $field_name => $field_details) {
// If we have terms defined
if (isset($data[$field_name][$language])) {
// Cycle through terms
foreach ($data[$field_name][$language] as $term) {
// If there is a term tid defined and it is an int
if (isset($term['tid']) && is_int((int) $term['tid'])) {
if (!isset($term['vid']) || in_array($term['vid'], $vocabs)) {
$category[$term['tid']] = taxonomy_term_load($term['tid']);
}
}
elseif (isset($term['tid']) && $term['tid'] == 'autocreate') {
// We're creating a new term
if (!isset($category['autocreate'])) {
$category['0'] = new stdClass();
$category['0']['names'] = array();
$category['0']->vid = $term['vid'];
}
$category['autocreate']['names'][] = $term['name'];
}
}
}
}
if (empty($category)) {
$category[] = '0';
}
return $category;
}