4

I recently inherited a legacy project that I've been trying to work with. I defined a custom menu using the menu hook but it looks like anonymous users can't access that menu and instead gets redirected to the user login page. This is a fairly large project and I'm trouble figuring out where exactly the call is intercepted and redirect. Any help would be great.

This is what the redirected looks like if it helps: localhost/user?destination=results

function test_results_menu() {
  $items = array();
  $items['results'] = array(
    'page callback' => 'display_test_results',
    'access callback' => 'test_results_resource_access'
  );
  return $items;
}

function test_results_resource_access() {
  return TRUE;
}

function display_test_results() {
  //  TODO Display results
  return "hi";
}

Update: The odd thing for me is that the project also recently got a rest endpoint using the services module which allows anonymous users to see the data there.

2

If you want your menu access by everyone set access callback TRUE(not need determine function and it pass TRUE,(maybe this is test and you want in future have condtional menu)).

function test_results_menu() {
  $items = array();
  $items['results'] = array(
     'title' => 'your title',
     'description' => 'menu description',
    'page callback' => 'display_test_results',
    'access callback' => TRUE,
  );
  return $items;
}


function display_test_results() {
  //  TODO Display results
   print "hi";
}

This will be work . please after any change in hook_menu clear your drupal cache.

  • Nope didn't work. My guess is that the previous developer used another module to sort out permissions and do the redirect but like I said the project is so large I'm having trouble figuring out what he was using. – Sathariel Sep 16 '12 at 16:05
  • 1
    what is you module name ? test_results? by default this code should work. – Yusef Sep 16 '12 at 16:17
  • 1
    If this isn't working, check to see if another module is doing a ANOTHERMODULE_menu_alter() and altering that menu item. – Jimajamma Sep 16 '12 at 16:32

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.