drupal get route current content type

To get the current content type in Drupal, you can use the routeMatch service to retrieve the route parameters and then access the node object to get the content type. Here's an example code snippet:

use Drupal\Core\Routing\RouteMatchInterface;

function mymodule_get_current_content_type(RouteMatchInterface $route_match) {
  // Get the node object from the route parameters.
  $node = $route_match->getParameter('node');

  // Check if the node object exists and get the content type.
  if ($node instanceof \Drupal\node\NodeInterface) {
    $content_type = $node->getType();
    return $content_type;
  }

  return NULL;
}

// Get the current route match service.
$route_match = \Drupal::routeMatch();

// Get the current content type.
$content_type = mymodule_get_current_content_type($route_match);

// Print the current content type.
if ($content_type) {
  print 'Current content type: ' . $content_type;
} else {
  print 'No content type found.';
}

Please note that this code assumes you are using Drupal 8 or later. If you are using an earlier version of Drupal, the code may need to be adjusted accordingly.