Community Documentation

Hide Author form from node dialogue

Last updated January 27, 2012. Created by pwolanin on June 11, 2006.
Edited by oskar_calvo, s_oneill. Log in to edit this page.

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:

<?php
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:

<?php
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.

About this page

Drupal version
Drupal 4.7.x

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.