0

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.

1 Answer 1

0

As i can see from the menu token that the module has a pre-released version for drupal 8 as development release, so maybe you could try it out or at least search in its code to find a way to accomplish your needs.

I have recently built a drupal 7 website and i have used the menu token to create a hover over drop down usermenu with username and profile picture.

See image below (i drawed in black on top of it because the site in not yet online) hover over drop down menu

If you like, i can right back small tutorial on how i achieved that !

1
  • Thank you but the menu token module (dev) hasn't been updated since 2013 and also I work on d8 which is different than d7.
    – Ismini
    Commented Jun 12, 2017 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.