You are here

function taxonomy_machine_name_update_term in Taxonomy Machine Name 8

Update term with machine name.

Parameters

\Drupal\taxonomy\TermInterface $term: Taxonomy term storage.

Return value

\Drupal\taxonomy\TermInterface The taxonomy term.

2 calls to taxonomy_machine_name_update_term()
taxonomy_machine_name_deploy_update_existing_terms in ./taxonomy_machine_name.deploy.php
Add machine_name for previously created terms.
taxonomy_machine_name_update_all_terms in ./taxonomy_machine_name.install
Update machine names for existing terms, usable both in batch and update.

File

./taxonomy_machine_name.module, line 266
This is the Taxonomy Machine Name module.

Code

function taxonomy_machine_name_update_term(TermInterface $term) {
  if (empty($term
    ->get('machine_name')
    ->first())) {
    $name = $term
      ->get('name')
      ->first()
      ->getValue()['value'];
    $term->machine_name = taxonomy_machine_name_clean_name($name);
    $term
      ->save();
  }
  return $term;
}