I am doing some access to content using hook_form_alter as there are problems using hook_access with content types defined outside of your module. If a user does not have access I am setting a message at the top of the page and I don't want to output the form. I have the following code.
function mymodule_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'cmyformm':
dsm($form);
$from = null;
dsm($form);
d开发者_JAVA技巧rupal_set_message('You do not have access to this page');
break;
}
}
The dsm however is returning the same information for $form even if I set it to null. How do I not display the form but a message?
I don't quite understand the question, but for starters you are setting $fROm
to null and not $fORm
. Setting for to null or just doing unset($form);
should do the trick.
Access control shouldn't be done at the form level. Access control should be implemented with hook_access or in the router's access arguments. If you must do this at the form level, use user_access() along with the defined roles that you have.
In addition to the typo as pointed out by @zeroFIG, you are really doing this access check in the wrong way. I have used the node_example module with sucess on all node types - none were defined in the same module as the hook_access. Have a look here: http://api.drupal.org/api/examples/node_example--node_example.module/6
精彩评论