Removing Log Message Field from Node Create

jvoorhe - February 8, 2007 - 15:42
Project:Drupal
Version:6.4
Component:node system
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

While I understand the purpose of the "log message" field in the node create form, I would like to remove it for my clients as it simply confuses them. Does anyone have a hack yet in the form.inc file that removes this?

#1

RobRoy - March 9, 2007 - 01:28
Version:5.1» 6.x-dev
Category:support request» feature request

IMO this should be a content types option so I'm setting to 6.x-dev, but for now you can create a module called remove_log_field.module with this:

<?php
/**
* Implementation of hook_form_alter().
*/
function remove_log_field_form_alter($form_id, &$form) {
  if (isset(
$form['#node']) && isset($form['log']) && $form_id == $form['#node']->type .'_node_form') {
   
$form['log']['#access'] = FALSE;
  }
}
?>

#2

Gabriel Radic - March 16, 2007 - 10:19

Hello RobRoy,

I created the .module as you suggested but it didn't work.

Ay other suggestion would be appreciated.

#3

earnie - March 16, 2007 - 11:55

Subscribing to post

#4

RobRoy - March 19, 2007 - 21:07

@Gabriel, is this in Drupal 5?

#5

Gabriel Radic - March 20, 2007 - 10:02

I m using Drupal 5.1 with no alteration of the core.

The module created as described above doesn't even appear on the modules list.

Thanks.

#6

RobRoy - March 20, 2007 - 22:09

Sorry, should have been more explcit. You'll need a .info file as well: http://drupal.org/node/101009.

#7

Zach Harkey - March 21, 2007 - 16:56

If you don't feel like creating and enabling a whole module for this, it's pretty easy to override the node form at the template level by adding the following function to your template.tpl.php:

<?php
/**
* Override node form
*/
function phptemplate_node_form($form) {
 
// Remove 'Log message' text area
 
$form['log']['#access'] = FALSE;
  return
drupal_render($form);
}
?>

#8

Gabriel Radic - March 21, 2007 - 21:35

The template change worked great.

Thanks for your help guys!

#9

RobRoy - June 26, 2007 - 10:27
Category:feature request» support request
Status:active» fixed

#10

Anonymous - July 10, 2007 - 10:45
Status:fixed» closed

#11

skassam - January 7, 2008 - 18:55

Any idea how to override the same field on node edit also?

TIA,
Shinan

#12

bsobolewska - September 3, 2008 - 14:46
Version:6.x-dev» 5.2

I have tried to place the code within the template.php (is it the same as template.tpl.php?) but I got the following error:

Fatal error: Cannot redeclare phptemplate_node_form() (previously declared in D:\wamp\www\portal\themes\zen\template.php:7) in D:\wamp\www\portal\themes\zen\template.php on line 518

Where the code around line 518 is:

// Add Form Start
function phptemplate_node_form($form) {
if ($form['form_id']['#value'] == 'ugevent_node_form') {
return _phptemplate_callback('event_add', array('form' => $form));
}

if ($form['form_id']['#value'] == 'qanda_node_form') {
return _phptemplate_callback('qanda_add', array('form' => $form));
}

}
// Add Form End

Then I thought that maybe template.php is indeed not the same as template.tpl.php so created one in the same folder themes\zen but nothing happened (no error and no result).

I must say I always get the same sort of error whenever trying to override the existing functions.
What am I doing wrong?
greetings,
Bogumila

#13

earnie - September 3, 2008 - 16:10

The easiest way may possibly be a hook_form_alter implementation in a module. For the $form_id matching node/create you simply set the '#type' to 'hidden' for the log message fields.

#14

jefftrnr - October 7, 2008 - 20:10
Version:5.2» 6.4

It looks like it works a bit differently in Drupal 6. It uses the same theme override function, but different keys in the $form array. I set it to a "hidden" type.

function phptemplate_node_form($form) {
  // Remove 'Log message' text area
  $form['revision_information']['#type'] = 'hidden';
  return theme_node_form($form);
}

Does this look wrong to anyone? It seems to work. I put it in my template.php file.

#15

Digital Deployment - December 18, 2008 - 09:48

Thanks - that did the trick for me!

I updated code just a bit to still be visible for people with the "edit post" permission:

<?php
function phptemplate_node_form($form) {
  
// Remove 'Log message' text area
  
$form['revision_information']['#access'] = user_access('administer posts');
   return
theme_node_form($form);
}
?>

#16

chris_huh - January 3, 2009 - 11:25

I tried that (version 6.8) and it doesn't do anything. Is there something i might have done wrong?

#17

chris_huh - January 3, 2009 - 12:14

Actually it works now. i think it just needed a bit of time to go through.

#18

jim0203 - January 10, 2009 - 13:04

@Digital Deployment:

Your code:

<?php
function phptemplate_node_form($form) {
  
// Remove 'Log message' text area
  
$form['revision_information']['#access'] = user_access('administer posts');
   return
theme_node_form($form);
}
?>

Is cool, but I don't seem to have the "administer posts" privilege available in my (pretty standard) D6 installation. I've therefore changed the code to:

<?php
function phptemplate_node_form($form) {
  
// Remove 'Log message' text area
  
$form['revision_information']['#access'] = user_access('view revisions');
   return
theme_node_form($form);
}
?>

Which links the ability to see the "Revision information" drop-down in the node creation form to the "view revisions" permission.

Using this technique you can pick a permission at will; it would be pretty simple to write a module which just added a new permission (or permissions) so you could specifically turn off the "Revision information" section of the node creation form.

On that note, could someone verify how easy it would be to write a module that allowed users to customize what sections of the node creation form were visible? I'm guessing it's just a matter of transcribing this function for each area of the node creation form and then adding the appropriate permissions to the permissions array.

#19

Damien Tournoud - January 10, 2009 - 13:10

This is *ugly*.

The good place to do this is in a hook_form_alter() implementation, *NOT* in the theme system. It works only by chance (because the log field is not mandatory).

#20

Zach Harkey - January 19, 2009 - 01:10

Whatever. The 'good' place to do this is through the core user interface. Specifically, in the main workflow settings for each content type.

Just like the upload module lets you enable/disable attachments, any module that adds optional fields to the node admin form should provide a way to disable the feature on a per content type basis.

#21

raintonr - March 26, 2009 - 09:38

Re: #1

The D6 version of this is:

<?php
function remove_log_field_form_alter(&$form, $form_state, $form_id) {
  if (isset(
$form['#node']) && isset($form['revision_information']) && $form_id == $form['#node']->type .'_node_form') {
   
$form['revision_information']['#access'] = FALSE;
  }
}
?>

#22

Onopoc - August 19, 2009 - 15:34

Another option is hiding 'Revision information' using CSS. To do so add the following style anywhere in your theme stylesheet file.

fieldset.collapsible {
     display: none;    /* Hiding all collapsible fieldsets in Drupal 6.x. Including 'Revision information' fieldset. */
}

Note that this will hide all collapsible fieldsets. Not just 'Revision information' fieldset.

#23

sin.star - September 3, 2009 - 10:13

Since I was writing my own node modules for defining content types I stumbled upon this, too. But opposing to include this in the MYMODULE_form function, I'd prefer the hook_form_alter implementation. Additionaly, I want the fields still be usable and just hide them from certain users. Fusing RobRoys (#1) and Onopocs (#22) proposals I came up with the following function to be included in my node modules:

<?php
// Invoke hook_form_alter to hide field(set)s defined by core modules.
function MYMODULE_form_alter(&$form, $form_state, $form_id)
{
  global
$user; // Bring $user object into scope if displaying shall depend on userid or role
  #if ( $user->uid != 1 ) // 0 -> Anonymous, 1 -> SuperAdmin, 2+ -> Authenticated users
 
if ( !in_array('USER ROLE NAME', $user->roles) ) // Check for role (using role name)
 
{
   
// add class 'hideme' to elements which shall be hidden
   
$form['revision_information']['#attributes'] = array('class' => 'hideme'); // Revision information
   
$form['author']['#attributes'] = array('class' => 'hideme'); // Author information
   
$form['options']['#attributes'] = array('class' => 'hideme'); // Publishing options
   
$form['xmlsitemap']['#attributes'] = array('class' => 'hideme'); // XML sitemap
   
$form['print']['#attributes'] = array('class' => 'hideme'); // Printer, e-mail and PDF versions
   
$form['path']['#attributes'] = array('class' => 'hideme'); // URL path settings
   
$form['menu']['#attributes'] = array('class' => 'hideme'); // Menu settings
    // Don't forget to add this class to your template CSS file:
    // .hideme { display: none; }
 
}
}
?>

Note: There are two possible ways included to hide it from certain users. You may either restrict display by user ID (deactivated above) or by role of user (active way in above snippet). Just replace MYMODULE by your modules name and USER ROLE NAME by the name of the role which is allowed to see revision information and such collapsible fieldsets.
And don't forget to define the 'hideme' class in your templates css.

 
 

Drupal is a registered trademark of Dries Buytaert.