| 5 node_access_example.module | node_access_example_form_alter( |
| 6 node_access_example.module | node_access_example_form_alter(&$form, $form_state) |
| 7 node_access_example.module | node_access_example_form_alter(&$form, $form_state) |
| 8 node_access_example.module | node_access_example_form_alter(&$form, $form_state) |
Implementation of hook_form_alter()
This module adds a simple checkbox to the node form labeled private. If the checkbox is labelled, only the node author and users with 'access private content' privileges may see it.
File
- developer/
examples/ node_access_example.module, line 133 - This is an example illustrating how to restrict access to nodes based on some criterion associated with the user.
Code
function node_access_example_form_alter($form_id, &$form) {
if ($form['#id'] == 'node-form') {
$form['private'] = array(
'#type' => 'checkbox',
'#title' => t('Private'),
'#description' => t('Check here if this content should be set private and only shown to privileged users.'),
'#default_value' => $form['#node']->private,
);
}
}
Login or register to post comments