8 – Using parameters in routes

I use the pathauto module to create URL aliases for all user account URLs.

/user/[uid] will become / u /[user:account-name]-[user:uid]

which means:

/ user / 36 will become / u / john-smith-36

In my custom module, I created a route to trigger a controller when / u / john-smith-36 / settoken? token = 123456 we access the URL.

The controller will:

  1. Retrieves the account of the currently logged in user.
  2. Update the text field field_user_push_token with the value of the query parameter:
    123456
  3. Register the account of the currently logged in user.
  4. Redirect the user to the page: /Thank you

I find a difficulty on how to use the settings in route for the URL of the user account!

save_push_token.routing

save_push_token.SavePushToken:
path: & # 39; / {user} / settoken & # 39;
by default:
_controller:  Drupal  save_push_token  Controller  SavePushTokenController :: SavePushToken & # 39;
requirements:
_permission: & # 39; access content & # 39;

SavePushTokenController.php

query-> get ("token");

// Load the account (user currently logged in).
// No need to load the user account because of {user}
// $ user =  Drupal  user  Entity  User :: load ( Drupal :: currentUser () -> id ());

// Set the (token).
$ user-> set (& # 39; field_user_push_token & # 39 ;, $ userpushtoken);

// Save the account (user currently logged in).
$ user-> save ();

// Redirect to the "/ thank you" page.
return new RedirectResponse (& # 39; / thanks & # 39;);

}
}

But simply the controller is not triggered when I access for example / u / john-smith-36 / settoken? token = 123456 we access the URL.

no help on how to properly use the settings in the routes?