0

I have configured my user path alias pattern as consultant/[user:name]. Now I need to have one custom path from my custom module as consultant/[user:name]/job. Here is my code in hook_menu.

 $items['user/%user/job'] = array(
'title' => 'Apply for job',
'page callback' => 'job_application_page',   
'access arguments' => array('access content'),
'file' => 'job.pages.inc',
'type' => MENU_CALLBACK,

);

I want the url as follows

For user Joan the path should be consultant/joan/job. But this is not working, giving an 404 error page

Do I miss something? Please advise.

  • What do you mean by this is not working? Any error message? Have you followed api.drupal.org/api/drupal/modules!system!system.api.php/…? As I don't see any 'page arguments' => array(1) being passed. – leymannx Jul 9 '18 at 9:55
  • Is %user an actual user object? Or is consultant a node type? – leymannx Jul 9 '18 at 10:02
  • Yes %user is an actual user object. – user4026 Jul 9 '18 at 10:10
3

You've picked user_load as your wildcard's load function - that takes an ID, and loads a user object. Your requirement is to load by username, which will work differently.

A function ending with _load doesn't exist for that, so you'll have to create your own:

$items['user/%MYMODULE_user_name/job'] = array(
...

function MYMODULE_user_name_load($name) {
  return user_load_by_name($name);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy