I have a custom menu MyMenu and I have four menu items. What I want to do is to add the current uid as a parameter at the end of the link.
In D7 I could use menu_tokens module which is not available on D8.
I tried to create a routing file in my custom module.
So in my routing file MY_MODULE.routing.yml I added :
MY_MODYLE.my_applications_redirect:
path: '/my-applications'
defaults:
_controller: '\Drupal\MY_MODULE\Controller\MyApplicationController::redirect_to_my_applications'
And in MyApplicationController.php :
namespace Drupal\MY_MODULE\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* A controller that redirects to the my applications page.
*/
class MyApplicationController extends ControllerBase {
/**
* {@inheritdoc}
*/
public function redirect_to_my_applications() {
global $base_url;
$user = \Drupal::currentUser();
$path = '/my-applications/'. $user->id();
$response = new RedirectResponse($base_url . $path);
$response->send();
}
}
Also in the menu I have set the path to /my-applications.
Do I miss something?
PS. The "my-applications" page is a panel page.