The hooks/functions you shown for the .module file can be removed, since Drupal 8 doesn't use hook_menu()
; therefore, Drupal will not use the littlurl_forward()
function defined from the module.
The code in the Controller.php file needs to be rewritten for Drupal 8, since:
- It should not access
$_GET['q']
- Instead of
drupal_goto()
, it should use the [redirect()][1] method of the controller
The first point means you should have three different methods you assign to the three different paths, which makes also more sense. It doesn't sense to assign the same method to three different paths, and the method then still need to understand for which path is being called.
As side notes, keep in mind that:
If you are editing a module that is already installed, or any of its files, you need to uninstall it first, since Drupal keep in a cache the list of hooks the module is implementing
The method of a class should not be named like
lower_case()
, butcamelCase()
From the code you are showing, it seems you are redirecting from n to node; if that is the case, then you can simply use a path alias
If instead you are redirecting from /n/node-id to /node/node-id, then it is probably better to use the Pathauto module which creates path aliases for nodes, taxonomy terms, and users (and lets you decide which pattern to use for those path aliases)
If the routes you are defining get arguments, you should define them in the routes, such as /n/{node}
If all the routes are doing is allowing to use /n/node-id instead of /node/node-id, I don't see much of a reason to write the code just for that [1]: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Routing%21UrlGeneratorTrait.php/function/UrlGeneratorTrait%3A%3Aredirect/8.2.x