For taxonomy term
$aliasManager = \Drupal::service('path_alias.manager');
$alias = $aliasManager->getAliasByPath('/taxonomy/term/'.$tidss);
For node
$aliasManager = \Drupal::service('path_alias.manager');
$alias = $aliasManager->getAliasByPath('/node/'.$id);
Taxonomy term path alias in twig tpl
<a href="{{ path('entity.taxonomy_term.canonical', {'taxonomy_term': node.field_taxonomy_reference.entity.tid.value}) }}">
<h2>{{ content.field_taxonomy_reference }}</h2>
</a>
To load a single term ID by term name and vocabulary in Drupal 8 you can use the following
$term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')
->loadByProperties(['name' => $term_name, 'vid' => 'job_category']);
$term = reset($term);
$term_id = $term->id();
1 comment:
Very interesting post...
How i get Taxonomy Term URL Path by tid in Drupal 8
Will definitely try it...
Drupal Development Company
Drupal Module Development Services
Post a Comment