1 taxonomy.module taxonomy_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items)

Implements hook_field_presave().

Create any new terms defined in a free-tagging vocabulary.

Related topics

File

core/modules/taxonomy/taxonomy.module, line 2016
Enables the organization of content into categories.

Code

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