function _exif_handle_taxonomy_field in Exif 7
handle taxonomy field.
Parameters
$terms:
$field_data:
1 call to _exif_handle_taxonomy_field()
- _exif_handle_field in ./
exif.module - handle field by delegating to specific type handler.
File
- ./
exif.module, line 325
Code
function _exif_handle_taxonomy_field($index, $language, $field, $field_type, &$field_data, $exif_section, $exif_name, $exif_value) {
$exif_value = _exif_handle_field_value_consistency($exif_value, $field);
$chosen_vocabulary = $field['settings']['allowed_values'][0]['vocabulary'];
if (isset($chosen_vocabulary)) {
$vocabularies = taxonomy_vocabulary_get_names();
if (is_array($vocabularies) && isset($vocabularies[$chosen_vocabulary])) {
$vocabulary = $vocabularies[$chosen_vocabulary];
$terms = taxonomy_get_term_by_name($exif_value, $chosen_vocabulary);
if (is_array($terms) && count($terms) > 0) {
$term = array_shift($terms);
$field_data[$language][$index]['tid'] = $term->tid;
}
else {
//TODO: make auto-creation optional even if vocabulary exist.
// if not exist, create it
//store full metadata in vocabulary
$terms = taxonomy_get_term_by_name($exif_name, $chosen_vocabulary);
if (is_array($terms) && count($terms) > 0) {
$parent_term = array_shift($terms);
}
else {
$terms = taxonomy_get_term_by_name($exif_section, $chosen_vocabulary);
if (is_array($terms) && count($terms) > 0) {
$section_term = array_shift($terms);
}
else {
$section_term = _exif_create_term($vocabulary->vid, $exif_section);
}
$parent_term = _exif_create_term($vocabulary->vid, $exif_name, $section_term->tid);
}
$term = _exif_create_term($vocabulary->vid, $exif_value, $parent_term->tid);
if (isset($term->tid)) {
$field_data[$language][$index]['tid'] = $term->tid;
}
}
}
}
}