Drupal Get Taxonomy Term From Route

The process of loading taxonomy term from routematch for Drupal 8, 9 and 10 is as follows.

$tax = \Drupal::routeMatch()->getParameter('taxonomy_term');
if ($tax instanceof \Drupal\taxonomy\TermInterface) {
 // $tax
}

We got the taxonomy from the route with the following code.

$tax = \Drupal::routeMatch()->getParameter('taxonomy_term');

With the code below, we confirmed that the entity we loaded is a taxonomy.

if ($tax instanceof \Drupal\taxonomy\TermInterface) {

 

Add new comment

Kısıtlı HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.