Drupal

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.

Drupal Get Node From Route

For Drupal 8 / 9 and 10, finding the node from the route is done with the following code.

$node = \Drupal::routeMatch()->getParameter('node');
if ($node instanceof \Drupal\node\NodeInterface) {
 // $node 
}

 

Drupal 8 Drush SQL Export

Using Drupal 8 Drush 9 you can export your database with the help of the following command.

drush sql-dump --result-file=name.sql

If you want your database to be exported as compressed, you can use the command below.

drush sql-dump --gzip --result-file=name.sql

 

Drupal 8 Drush SQL Import

You can use the following code to import mysql using Drupal 8 drush 9. You can change the database name in the following command to match the name of the database.

drush sql-cli < database.sql

 

Drupal 8 Taxonomy Term Load

To access taxonomy terms in Drupal 8, you must include the Term class in your project.

use Drupal\taxonomy\Entity\Term;

In order to load the taxonomy, you must send the tid to the term: load function.

$term = Term::load($tid);

The getName function is used to get the name of the taxonomy loaded with the term: load function.

Drupal 8 Get Current User ID

The following command must be used to get the current user id for drupal 8 and drupal 9.

\Drupal::currentUser()->id();