Hide Author form from node dialogue

Note from the moderator: Thank you for sharing the snippet with the Drupal community. However, users are strongly advised against editing the core module files. The result described below is better achieved by implementing a mini-module that uses hook_form_alter to change the node form.

I wanted my users to be able to create new versions of existing nodes, which can be done easily by giving them permissions to Administer content in the Node module section of the Admin > Permissions

...however that also let users change the author of the existing node, which I didnt want. Looked around a bit and finally hacked the node.module script (in Modules folder).

From approx line 1628 you find:

if (user_access('administer nodes')) {
// Node author information
$form['author'] = array('#type' => 'fieldset', '#title' => t('Authoring information'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => 20);
$form['author']['name'] = array('#type' => 'textfield', '#title' => t('Authored by'), '#maxlength' => 60, '#autocomplete_path' => 'user/autocomplete', '#default_value' => $node->name ? $node->name : '', '#weight' => -1, '#description' => t('Leave blank for %anonymous.', array('%anonymous' => theme('placeholder', variable_get('anonymous', 'Anonymous')))));
$form['author']['date'] = array('#type' => 'textfield', '#title' => t('Authored on'), '#maxlength' => 25, '#description' => t('Format: %time. Leave blank to use the time of form submission.', array('%time' => $node->date)));

I changed this to:

if (user_access('administer nodes')) {
// Node author information
global $user;
if ($user->uid == 1) {
$form['author'] = array('#type' => 'fieldset', '#title' => t('Authoring information'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => 20);
$form['author']['name'] = array('#type' => 'textfield', '#title' => t('Authored by'), '#maxlength' => 60, '#autocomplete_path' => 'user/autocomplete', '#default_value' => $node->name ? $node->name : '', '#weight' => -1, '#description' => t('Leave blank for %anonymous.', array('%anonymous' => theme('placeholder', variable_get('anonymous', 'Anonymous')))));
$form['author']['date'] = array('#type' => 'textfield', '#title' => t('Authored on'), '#maxlength' => 25, '#description' => t('Format: %time. Leave blank to use the time of form submission.', array('%time' => $node->date)));
}

This allows only the admin to change the author of existing nodes.

- Soren ONeill, Denmark

NB. Please note, I have absolutely no idea whether this would have security implications, though I doubt it.

is there maybe an example to

momper - February 15, 2008 - 15:36

is there maybe an example to do this without editing the core module files?

thanks and greetings momper

 
 

Drupal is a registered trademark of Dries Buytaert.