public function Utility::faqAskGetTerms in FAQ_Ask 8
Helper function to get FAQ_Ask term.
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.
1 call to Utility::faqAskGetTerms()
- faq_ask_node_insert in ./
faq_ask.module - Implements hook_node_insert().
File
- src/
Utility.php, line 222 - Contains \Drupal\faq_ask\Utility.
Class
- Utility
- Contains static helper functions for FAQ module.
Namespace
Drupal\faq_askCode
public function faqAskGetTerms($data) {
$category = array();
// Get fields relevant for the faq node.
$fields = \Drupal::entityManager()
->getFieldDefinitions('node', 'faq');
foreach ($fields as $name => $properties) {
if (!empty($properties
->getTargetBundle())) {
$fieldSettings = $properties
->getSettings();
if ($fieldSettings['handler'] == 'default:taxonomy_term') {
$fields_new[$name] = $properties;
}
}
}
// Parse through all tagging fields in use.
foreach ($fields_new as $field_name => $field_details) {
if (!empty($properties
->getTargetBundle())) {
// If we have terms defined.
$faq_term = $data
->get('field_faq_category')
->getValue();
if (is_array($faq_term)) {
// Cycle through terms.
foreach ($faq_term as $term) {
// If there is a term tid defined and it is an int.
if (isset($term['target_id']) && is_int((int) $term['target_id'])) {
$category[$term['target_id']] = taxonomy_term_load($term['target_id']);
}
}
}
}
if (empty($category)) {
$category[] = '0';
}
return $category;
}
}