2

I will wish to create a privileged space for some users.

I create a role 'Candidate'. I assigned permission 'access user profiles' has this role. I create a user that uses this role. (eg, foo)

Secondly, I create a menu (see below)

$items['candidate/%candidate'] = array(
  'title'            => t('My candidate space'),
  'description'      => '',
  'page callback'    => 'cel_configuration_custom_page',
  'page arguments'   => array(1),
  'access arguments' => array('access user profiles'),
  'access callback' => TRUE,
);

Then a linked function

function cel_configuration_custom_page($args){
  return 'custom';
}

Finally, I have emptied the cache.

When I go on the candidate/1 page with my account 'toto' or account 'admin', I have not found page.

Why?

2

Try the following code:

    $items['candidate/%user'] = array(
      'title'            => t('My candidate space'),
      'page callback'    => 'cel_configuration_custom_page',
      'page arguments'   => array(1),
      'access arguments' => array('access user profiles'),
    );

    function cel_configuration_custom_page($account){
      return 'Custom page for ' . $account->name;
    }

You can't use %candidate as an argument for user accounts. Also, if you want to restrict access by a particular permission, don't set access callback to TRUE as that will grant access to everyone.

  • +1 for spotting the thing I wasn't spotting! %candidate in the menu path means Drupal will try to call candidate_load function, and that's probably what's causing the 404. Whereas %user in the menu path will try to call user_load function. – Beebee May 26 '15 at 9:26
1

Thanks for your answers.

To solve the problem I use as my variable in url% or ['candidate /%'] and it works properly.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.