function hook_taxonomy_term_insert

Act on taxonomy terms when inserted.

Modules implementing this hook can act on the term object when saved to the database.

Parameters

Drupal\taxonomy\Term $term: A taxonomy term entity.

Related topics

3 functions implement hook_taxonomy_term_insert()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

entity_crud_hook_test_taxonomy_term_insert in drupal/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module
Implements hook_taxonomy_term_insert().
path_taxonomy_term_insert in drupal/core/modules/path/path.module
Implements hook_taxonomy_term_insert().
taxonomy_test_taxonomy_term_insert in drupal/core/modules/system/tests/modules/taxonomy_test/taxonomy_test.module
Implements hook_taxonomy_term_insert().

File

drupal/core/modules/taxonomy/taxonomy.api.php, line 157
Hooks provided by the Taxonomy module.

Code

function hook_taxonomy_term_insert(Drupal\taxonomy\Term $term) {
  if (!empty($term->synonyms)) {
    foreach (explode("\n", str_replace("\r", '', $term->synonyms)) as $synonym) {
      if ($synonym) {
        db_insert('taxonomy_term_synonym')
          ->fields(array(
          'tid' => $term->tid,
          'name' => rtrim($synonym),
        ))
          ->execute();
      }
    }
  }
}