Drupal 7: menu token and me Alias are not working

Currently, modules Menu Token and me Alias are not working (8/1/2014). There may be a way to get them to work … each has lots of notes around the internet that indicates they are working on & off, with lots of proposed workarounds. Trying workaround after workaround, I could not get them to work consistently or conveniently. Trying to use either, insert tokens in a menu is a problem. I have a solution. The solution is not sophisticated or convenient, but, it appears to work consistently. Hopefully, it will work consistently until the menu token or me Alias modules work consistently.

Unfortunately, the work around requires:

  • Some familiarity with php
  • Faking out the menu validation
  • use of hook_url_outbound_alter

To insert the current user_id tokens into the path in a menus:

  • Step 1: Realize you really want the path “user/uid/history”
  • Step 2: Create a basic content page with url of “user/uid/history”
  • Step 3: Select the menu you would like to add this entry too, add the menu label, path user/uid/history and save, the entry will be allowed because their is a valid page defined at user/uid/history.
  • Step 4: Before leaving the menu, check the actual node id that is automatically inserted in place of path you specified (ex. node/13 might be the real address)
  • Step 5: In the template.php, create the THEME_url_outbound_alter function as follows:
    
     
      function THEME_url_outbound_alter(&$path, &$options, $original_path) {
        if ($path == "node/13") {     // check $path == 
                                      //       the dummy address you created
          global $user;               // prepare to get the token uid value
                                      // build the $path with the current 
                                      // user uid 
          $path = 'user/' . $user->uid . "/history" ;
                                      // Set $options['alias'] = path you 
                                      // want accessed
          $options['alias'] = $path;  
        }
        // repeat the previous path redefine for all pages you would like
        // to include the token uid.   Other tokens may be dealt with in 
        // a similar manner. 
      
      }   
    
    

Leave a Reply