3

I'm trying to create a menu link within the admin area that includes a urlencoded() copy of the current URL as a tail to the link URL, so that the code invoked can redirect back to the current page when it's done its job.

However, as soon as the string returned by my _to_arg() callback contains a URLencoded string (Or specifically any string containing a % character), Drupal drops access rights to that menu, and the link is hidden.

Sample code below:

/**
 * Implements hook_menu().
 */
function admin_bar_menu() {

  $items['admin/bar/%test'] = array(
    'title' => 'Admin Bar Test',
    'page callback' => '_admin_bar_redirector',
    'page arguments' => array(2),
    'access callback' => 'user_access',
    'type' => MENU_NORMAL_ITEM,
    'weight' => 15,
  );

  return $items;
}



function test_to_arg ( $arg, $map, $index ) {

  // 1. Link is shown, but is of the form /admin/bar/admin/appearance,
  // so the desired string (admin/appearance) can't be retrieved
    // return $_GET['q'];

  // 2. Link is hidden
  // return urlencode($_GET['q']);

  // 3. Link is hidden
  // return 'foo%bar';

}


function _admin_bar_redirector($destination) {
    drupal_goto($destination);
}

I'm pretty sure this is being caused by the following code in menu.inc (Line 911 - d7.14):

// Skip links containing untranslated arguments.

if (strpos($item['href'], '%') !== FALSE) {
  $item['access'] = FALSE;
  return FALSE;
}

Can anyone suggest a potential avenue for a fix to the code in menu.inc - or is there a better way to achieve what I'm trying to do?

1
  • I've just hit this also and I agree, it's irritating.
    – Christian
    Oct 9, 2013 at 4:49

1 Answer 1

2

I've assumed this needs fixing in core, so logged it here - any insights welcome!

http://drupal.org/node/1822004

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.