function taxonomy_field_presave

Implements hook_field_presave().

Create any new terms defined in a freetagging vocabulary.

Related topics

File

modules/taxonomy/taxonomy.module, line 1902

Code

function taxonomy_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
    foreach ($items as $delta => $item) {
        if ($item['tid'] === 'autocreate') {
            $term = (object) $item;
            unset($term->tid);
            taxonomy_term_save($term);
            $items[$delta]['tid'] = $term->tid;
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.