How to use menu_get_object()?
See
https://drupal.stackexchange.com/a/202185/45409

In Drupal 8, you can get url arguments based on what's in the routing.

To get the id alone:

$nid = \Drupal::routeMatch()-&gt;getRawParameter('node');


If you plan to load the node object, you can simply get it this way:

$node = \Drupal::routeMatch()-&gt;getParameter('node');


To find the parameter names, you can use:

$possible_parameters = \Drupal::routeMatch()-&gt;getParameters();


To find the node type, use:

$node-&gt;bundle();