I have several things I want to check before a user may create a node. So, if the user visits node/add/proposal I want to check if he may do so, so I wrote a module:
function proposals_menu() {
$items['node/add/proposal'] = array(
'title' => t('Proposal'),
'access callback' => 'proposals_access',
);
return $items;
}
function proposals_access() {
$cond1;
$cond2;
...
return cond1 && cond2 && ....;
}
When I click on add content -> proposal I get a blank page. What am I missing?
To override existing menu items you need to use
hook_menu_alter()
instead ofhook_menu()
. e.g.But there's also
hook_node_access()
which would be preferable to use for (as the name suggests) checking node access. e.g.Assuming you populate
$allow_access
with your access check. Be sure to use the$account
object that's passed to the hook to verify the operation against that user object. Don't depend on the currently logged in user, which will not always be the same.