0

I made a custom module in Drupal 7 with a simple page.

I used hook_menu to make permission :

function mymodule_menu() {     
  $items = array();
  $items['prestart'] = array(
            'title'             => t('Prestart page'),
            'page callback'     => array('mymodule_show_page'),
            'access arguments'  => array('access content'),
            'access callback'   => 'mymodule_isUserAuthenticated',
            'type'              => MENU_NORMAL_ITEM,
  );
  return $items;
}

The function to check if the user is authenticated :

function mymodule_isUserAuthenticated() {
   if (!user_is_logged_in()) {
       return FALSE;
    }
     return TRUE;
  }
}

After I created block (admin/structure/block) and I added to the page.

Problem : If I go on the page in a private navigation tab (so not connected), I can see You are not authorized to access this page but all blocks are displayed.

How can I fix it ?

1 Answer 1

1

You probably need to adjust the visibility settings of your blocks (see screenshot below). You can, for instance, restrict the visibility to authenticated users only.

It is also possible to do it programmatically. See this question, for some guidance.

enter image description here

1
  • Haha... I missed this block configure because I was thinking that the page permission was the top level for my content. Thanks.
    – Promo
    May 20, 2016 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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