drupal 8 get current page node code example
Example 1: drupal 8 get page node
// Get page node.
$node = \Drupal::routeMatch()->getParameter('node');
// Get page entity.
$params = \Drupal::routeMatch()->getParameters()->all();
$entity = reset($params);
Example 2: Drupal 8 get page node current path
// Get current path.
$current_path = \Drupal::service('path.current')->getPath();
$path_alias = \Drupal::service('path.alias_manager')->getAliasByPath($current_path);