Handle taxonomy field.

Parameters

int $index:

string $language:

array $field:

string $field_type: _data

string $exif_section:

string $exif_name:

string $exif_value:

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 385

Code

function _exif_handle_taxonomy_field($index, $language, array $field, $field_type, array &$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;
                }
            }
        }
    }
}