taxonomy_get_parents drupal 8

In Drupal 8, the taxonomy_get_parents function is not available. Instead, you can use the Drupal\taxonomy\Entity\Term::loadParents method to retrieve the parent terms of a given term.

Here's an example of how you can use loadParents:

// Load the term entity.
$term = \Drupal\taxonomy\Entity\Term::load($term_id);

// Get the parent terms.
$parents = $term->loadParents();

// Loop through the parent terms.
foreach ($parents as $parent) {
  // Do something with the parent term.
  // For example, print the parent term name.
  print $parent->getName();
}

This code loads the term entity using the load method and then retrieves its parent terms using the loadParents method. You can then loop through the parent terms and perform any necessary actions. In this example, we simply print the name of each parent term.

Please note that you need to replace $term_id with the actual ID of the term you want to retrieve the parents for.