0

I'm new to Drupal so am struggling here. I've created a checkbox field and the goals is that when it is checked it redirects anonymous to the 404 page.

I have the following condition:

function page_module_preprocess_page(&$variables) {

 // code to retrive checkbox value

 if (user_is_anonymous() && $page_hidden_value == 1) {
    drupal_not_found();
  }
}

But this doesnt work.

However, interestingly enough if I do the reverse and check that the user is logged in (!user_is_anonymous()) it does work and does redirect to 404.

I can DPM the value of the checkbox ($page_hidden_value) so I know that's working correctly.

Would anyone know what could be going on here?

0

I have had some odd experiences with user_is_anonymous(). Try using negation with user_is_logged_in(). For example:

if (!user_is_logged_in()) {
    // Do stuff
}
| improve this answer | |
  • Thanks, but same result unfortunately. – MeltingDog Oct 26 '17 at 22:27
0

I kind of got this working with drupal_goto

 if (user_is_anonymous() && $page_hidden_value == 1) {
    drupal_goto('/404');
  }
| improve this answer | |

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.