0

Does Drupal have any tool to generate URL from hook_menu() link pattern? Something like this:

some_function('node/%/edit/something/%', array(1, 19))

that will generate this URL: http://maindomain.com/node/1/edit/something/19.

1 Answer 1

1

I don't think Drupal has a function for that specific case - at least not one that I've come across.

Obviously lots of ways to accomplish it though. Without writing your own function, my thought was to make use of the format_string() and url() functions.

$args = array(
  '@arg_1' => 1,
  '@arg_4' => 19,
);
$path = format_string('node/@arg_1/edit/something/%arg_4', $args);
$url = url($path, array('absolute' => TRUE)); // I used absolute here because
                                              // your example has an absolute
                                              // path. It shouldn't be
                                              // necessary though.
print $url // Prints `http[s]:[domain.com]/[base_path]/node/1/edit/something/19`

Of course, you could take that a step further and use the l() function to create an actual link, but I'm not sure what your exact use case is.

1
  • Thanks for the answer ;). Everything is ok, but the arguments in the pattern are the same and I'm taking them from hook_menu() keys. So it's like link/%/part1/%/something. I think, that I must write my own function..
    – Jazi
    Oct 21, 2014 at 6:52

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.