i would like to get the user id of the user profile page being browsed into a menu...i tried adding this with token starter, but it didnt work

$tokens['user']['uid']= t("The unique ID of the user account.");

thanks!

CommentFileSizeAuthor
#2 menu_token_type_extension.patch963 bytescitlacom

Comments

ygerasimov’s picture

Priority: Critical » Normal

At the moment only global tokens are supported. But it would be nice feature if we can support node tokens as well (if /node/X page is viewed).

Anyhow you will need to export profile user uid token in your own module.

I will try to implement 'specific' tokens replacement and advise in this issue.

citlacom’s picture

Status: Active » Needs review
Issue tags: +devel patch
StatusFileSize
new963 bytes

Here is the patch for the implementation of support for users and node tokens and the extension of the help info that describe all the available tokens.

khalor’s picture

Patch applies cleanly and I see the additional tokens in the available replacements patterns but using them in a menu path results in:

The path 'path/to/[token-value]' is either invalid or you do not have access to it

dealancer’s picture

@Khalor probably it happens when your are not seeing node/user profile, that's why this token could no be applied.

In general case there could be several possible cases of using node/user/taxonomy tokens, etc...

1) Context case: module could parse token in the menu title/path for the entity (node/user profile) that is being viewed.
2) Manually selected case: module could parse token for specified entity.
3) Probably more...

In general this is an Idea how it should look like:

Node tokens [v]
    [ ] Disabled
    [*] Context
    [ ] Manually selected
        Node [___________________o]
User tokens [v]
    [ ] Disabled
    [ ] Context
    [*] Manually selected
        User [_admin_[1]_________o]
Other...

We need to be able other modules to extend this functionality, hence we need a hook, which allows to add different kinds of menu token handlers for the tokens. Basically there should be an callback function which returns object.

hook_menu_token(&$tokens) {
  $token['<token_type>'] => array( // user, node, etc
    '<menu_token_handler_type>' => array(
      'title' => '<title>',
      'object_callback' => '<function_name>',
    )
  );
}

We need somehow to be able to alter form elements probably using form_later functions. Also we need to add a checkbox "Hide menu item if it could not be parsed".

develcuy’s picture

Priority: Normal » Major
brunorios1’s picture

Assigned: Unassigned » brunorios1

i get this error when applying the patch.

patch: **** Only garbage was found in the patch input.

brunorios1’s picture

i applyied the patch manually...

i used the token [nid]...

but in the node, the link of the menu link was printed node/[nid]/pictures...

dealancer’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

I have created separate brunch for it: http://drupalcode.org/project/menu_token.git/shortlog/refs/heads/7.x-1.x.... I am actually working on 7th version of this module, after it would be finished we could back-port changes.

dealancer’s picture

Status: Needs review » Needs work

It still needs work to have some kind of form support for the handlers.

dealancer’s picture

It still needs work to have some kind of form support for the handlers.

dealancer’s picture

Assigned: brunorios1 » Unassigned
dealancer’s picture

Assigned: Unassigned » dealancer
btopro’s picture

sub, though I was able to get this working by adding my own version of the alter hook used in the module

function YOURMODULE_translated_menu_link_alter(&$item, $map) {
  $mlid = $item['mlid'];
  $menu_token_item = menu_token_get($mlid);

  // Check whether we should replace the path.
  if (isset($menu_token_item)) {
    // If item is generated by admin menu module, tokens should not be replaced and
    // indicator that tokens are used should be shown.
    if (_menu_token_menu_admin($item)) {
      $item['title'] .= theme('menu_token_uses_tokens');
      $item['localized_options']['html'] = TRUE;
    }
    else {
      // Replace with tokens.
	  $arg_node = node_load(arg(1));
      $item['title'] =  token_replace($item['title'], 'node',$arg_node );
      $item['link_path'] = token_replace($menu_token_item['link_path'], 'node',$arg_node );
      $item['href'] = $item['link_path'];

      // Override active trail if showing front page but translated link is not to front page.
      // NOTE: This relies on any parent of a tokenised menu item having "option" flag "alter" set,
      // which is most easily achieved by setting it to use token translation but not specifying a token.
      // Otherwise parent does not get processed through this function and because its untranslated child has
      // an href of <front>, the menu system thinks it is part of the active trail to the front page.
      if (drupal_is_front_page() && $item['href'] != drupal_get_normal_path(variable_get('site_frontpage', 'node'))) {
        $item['in_active_trail'] = FALSE;
      }

      // Check whether path is external.
      if (menu_path_is_external($item['link_path'])) {
        return;
      }

      // Load menu_item and check access.
      if ($menu_item = menu_get_item($item['link_path'])) {
        $item['access'] = $menu_item['access'];
        return;
      }

      $item['access'] = FALSE;
    }
  }
}

This allowed me to use the node arguments which include OG stuff (horay)

fubhy’s picture

Status: Needs work » Fixed

We now support plugins for advanced tokens like this... The most basic tokens are working (node from context, user from context, taxonomy term from context) and many others are to come. Check out this new feature in the latest dev version.

brunorios1’s picture

really? this is great!
for which version? D6, D7 or both?

thanks!

fubhy’s picture

Currently only D7. I don't work with D6 and am therefore not really interested in a D6 backport.

btopro’s picture

That code I have posted is D6. If you download ELMS there is a working example that has some global tokens in it as I'll be dropping this project in favor of the functionality I've included.

fubhy’s picture

The code in #13 might cause funny behavior on pages that are not node pages since it just blindly includes node_load(arg(1)) as a node not even knowing if arg(1) refers to a node. If you want a real implementation for this for D6 you might want to backport my code to D6.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

dealancer’s picture

I have added code to user defined and random handlers. However they still needs to be updated, so I am creating new issue.

dealancer’s picture

dealancer’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Closed (fixed) » Needs work

Now we need to back port it to D6.

klonos’s picture

Till #750352: Provide an option to also offer dev builds as updates if they are newer - for advanced users & beta testers is fixed, can someone please update the latest devs (both 6.x & 7.x) so that they are newer than stable ones? Thanx in advance ;)

zarudnyi’s picture

Hi! Is there any progress?
I just trying to use this module with OG for group menu customizing.

protoplasm’s picture

This is a feature for D6 that I would very much appreciate as well. I've been looking for a way to dynamically create menus for different organic groups. This seems like the ideal solution. Is there any way to create a customized token workaround while waiting for a backport from D7? Thanks.

zarudnyi’s picture

protoplasm, you can use Panels with custom panes for creating menu for OG. Sorry for off topic.

jwilde’s picture

Are there any near term plans to add functionality to support additional tokens?

Thanks, Jim

penyaskito’s picture

The workaround at [#973882-13: additional tokens needed] worked for me.

markconroy’s picture

Where do you add [#973882-13: additional tokens needed] to get it to work?

develcuy’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

D6 is discontinued.

develcuy’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

This is not required anymore, since the integration with Entity API allows to have tokens from all configure entities.