public static function FeedImportFilter::setTaxonomyTerms in Feed Import 7
Same name and namespace in other branches
- 8 feed_import_base/filters/feed_import_default_filters.php \FeedImportFilter::setTaxonomyTerms()
- 7.3 feed_import_base/filters/feed_import_default_filters.php \FeedImportFilter::setTaxonomyTerms()
- 7.2 feed_import_filter.inc.php \FeedImportFilter::setTaxonomyTerms()
Save specified taxonomy terms to vocabulary
Parameters
mixed $name: A string or an array of strings
int|string $voc: (optionally) Vocabulary id/name
Return value
mixed Fetched and inserted tids
File
- ./
feed_import_filter.inc.php, line 246 - This class contains filter functions for feed import
Class
- FeedImportFilter
- @file This class contains filter functions for feed import
Code
public static function setTaxonomyTerms($name, $voc = 0) {
if (!is_numeric($voc)) {
$voc = self::getVidFromName($voc);
}
if (!is_array($name)) {
$name = array(
$name,
);
}
$tids = array();
$existing = self::getTaxonomyIdByName($name, $voc);
if (!empty($existing)) {
$existing = taxonomy_term_load_multiple($existing, array(
'vid' => $voc,
));
foreach ($existing as &$term) {
$tids[drupal_strtolower($term->name)] = $term->tid;
$term = NULL;
}
}
unset($existing);
foreach ($name as &$term) {
if (!isset($tids[drupal_strtolower($term)])) {
$t = new stdClass();
$t->vid = $voc;
$t->name = $term;
taxonomy_term_save($t);
$tids[$t->name] = $t->tid;
$t = NULL;
$term = NULL;
}
}
return $tids;
}