Posted by jvoorhe on February 8, 2007 at 3:42pm
Jump to:
| Project: | Drupal core |
| Version: | 7.x-dev |
| Component: | node system |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
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?
Comments
#1
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
Hello RobRoy,
I created the .module as you suggested but it didn't work.
Ay other suggestion would be appreciated.
#3
Subscribing to post
#4
@Gabriel, is this in Drupal 5?
#5
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
Sorry, should have been more explcit. You'll need a .info file as well: http://drupal.org/node/101009.
#7
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
The template change worked great.
Thanks for your help guys!
#9
#10
#11
Any idea how to override the same field on node edit also?
TIA,
Shinan
#12
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
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
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
Thanks - that did the trick for me!
I updated code just a bit to still be visible for people with the "edit post" permission:
<?phpfunction phptemplate_node_form($form) {
// Remove 'Log message' text area
$form['revision_information']['#access'] = user_access('administer posts');
return theme_node_form($form);
}
?>
#16
I tried that (version 6.8) and it doesn't do anything. Is there something i might have done wrong?
#17
Actually it works now. i think it just needed a bit of time to go through.
#18
@Digital Deployment:
Your code:
<?phpfunction 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:
<?phpfunction 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
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
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
Re: #1
The D6 version of this is:
<?phpfunction 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
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
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.
#24
Thank you very much for this code, worked great in 5.x Amadeu theme!
#25
Good work.
In my case I wanted to know if my user had one of a number of possible roles so I changed the IF condition to
<?phpif ( !(int)array_intersect(array('AccountAdmin','Partnerl','SuperUser'), $user->roles))
?>
#26
Subscribing
#27
Note that after implementing this, I had an issue with the position of my 'save' and 'preview' buttons. Because the hook is modifying the array, it's shuffling the order - so any form element that doesn't have weight set explicitly is going to be misplaced. The fix is to add '#weight' to the elements:
<?phpfunction phptemplate_node_form($form) {
// Remove 'Log message' text area
$form['revision_information']['#access'] = FALSE;
$form['buttons']['#weight'] = 100;
return drupal_render($form);
}
?>
#28
I've created a module to do this: http://drupal.org/project/removelogmessage
#29
Thank you for the module, works like a charm!
#30
Oh cool I'm glad it worked for you!
#31
This worked for me!! :)
#32
This worked for me!! :) Thanks raintonr
#21
Posted by raintonr on March 26, 2009 at 4:38am
Re: #1
The D6 version of this is:
<?phpfunction 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;
}
}
?>
#33
[quote=flamingvan]
I've created a module to do this: http://drupal.org/project/removelogmessage
[/quote]
Hi, Many thanks for the great work, but I had an issue using it ! (http://drupal.org/node/1203394)
Any suggestions please !
#34
Hi, Many thanks for the great work, but I had an issue using it ! (http://drupal.org/node/1203394)
Any suggestions please !
#35
This "Revision information" field does not make any sense on node creation. It should be removed from node create forms in core, not in contrib modules.