Posted by ofridagan on May 30, 2008 at 7:47pm
I want to let users edit only the body of a node but not the title (which the admin sets).
How can I do it?
I want to let users edit only the body of a node but not the title (which the admin sets).
How can I do it?
Comments
I can't imagine Drupal has this functionality out of the box
It seems like you'd probably have to write a module that hooks into the update process, then checks to see if the user who made the change is an administrator.
hook_form_alter
The hook_form_alter will allow you to remove this field unless the user has the required rights. Much better never to show the title field in the edit forms. This does require custom coding, something similar to:
<?php
/**
* Implementation of hook_perm
* This gives a new role in the admin section, just for this task
*/
function MYMODULE_perm() {
return array('administer node titles');
}
function MYMODULE_form_alter(&$form, $form_state, $form_id) {
// Check that the form is a content type edit/create form
if (isset($form['#node']) && $form['#node']->type .'_node_form' == $form_id) {
// If they do not have the title permission, hide the title field
if(!user_access('administer node titles') {
$form['title']['#type'] = 'value';
}
}
}
?>
I haven't tested/run this code, but it should guide you towards what you require.
Alan Davison
www.caignwebs.com.au
Alan Davison
Back roads somewhere in South America
Build your own module and use hook alter
function yourmodulename_form_yournodetypename_node_form_alter(&$form, &$form_state) {if(!is_null($form['nid']['#value'])) {
$form['title']['#type'] = 'hidden';
}
}
This could prevent anyone to modify title value.
Hello World
correction
<?php
/**
* Implementation of hook_perm
* This gives a new role in the admin section, just for this task
*/
function MYMODULE_perm() {
return array('administer node titles');
}
function MYMODULE_form_alter(&$form, $form_state, $form_id) {
// Check that the form is a content type edit/create form
if (isset($form['#node']) && $form['#node']->type .'_node_form' == $form_id) {
// If they do not have the title permission, hide the title field
if (!user_access('administer node titles')) {
$form['title']['#type'] = 'value';
}
}
}
?>
----
http://picxelplay.com
"After I'm gone, your earth will be free to live out its miserable span of existence, as one of my satellites, and that's how its going to be."
Use #access FAPI property
Even better :)
<?phpfunction MYMODULE_form_alter(&$form, $form_state, $form_id) {
// Check that the form is a content type edit/create form
if (isset($form['#node']) && $form['#node']->type .'_node_form' == $form_id) {
// If they do not have the title permission, hide the title field
$form['title']['#access'] = user_access('administer node titles');
}
}
?>
Alan Davison
Back roads somewhere in South America
uninstalling auto_nodetitle
I succeeded setting automatic node titles via Rules in Drupal 6, now I would like to remove the required Node Title field from form submissions for a given Content Type (I don't care about 'administer node titles' permissions). Could you please suggest a mini-module to that purpose? I have no PHP knowledge, but I guess it wouldn't be much different from above... Thx.
You are right
You are right :)
<?phpfunction MYMODULE_form_alter(&$form, $form_state, $form_id) {
// Check that the form is a content type edit/create form
if (isset($form['#node']) && $form['#node']->type .'_node_form' == $form_id) {
// If they do not have the title permission, hide the title field
$form['title']['#access'] = FALSE;
}
}
?>
This will eliminate all title fields from showing in the CMS.
Alan Davison
Back roads somewhere in South America
getting more than I bargained for :-)
Ok, the title setting has gone, as expected, but (with stock Garland) I am now getting "You don't have Javascript enabled" from Hierarchical Select form element (first position in form, right before title). If I disable the minimodule then JS is ok. It looks like the taxonomy drop-down selector and the node title are somehow interfering.
You could use the FAPI
You could use the FAPI #prefix/#suffix attributes to hide the title using a div that has the CSS style of display:none;. The JScript should still work with the hidden title. Remove the #access line as this prevents the HTML form being rendered. As title is required, you may need to set this to false or prepopulate it with a dummy value
Alan Davison
Back roads somewhere in South America
Thank you!
I hoped I'll find a way to hide the title in the 'edit' form.
Now, I just need to learn how to write a Drupal module... finally found a reason to do it :-)
Module Available
I've created a module to do this sort of thing. Check it out here. I developed it in response cck field permissions and token/auto nodetitle not playing nicely together but it should suit your purposes.
Drupal 6
Hi I'm trying to do the same thing in Drupal 6, is there any easy way to prevent users edit node title or do I have to go into hard coding?
What I want to achive is that once a node is published, the owner of the node would only be able to edit the body of the node but not the title. Any idea how to do it?
Thanks.
Title Coding in Drupal 6
Drupal URL will look like this when ADD node: node/add/account-company --> arg(0)/arg(1)/arg(2)/ ......
To prevent only for ADD node then check: arg(1)= 'add'
To prevent only for EDIT node then check: arg(1)= 'edit'
this is node/xxx/edit so it
this is node/xxx/edit so it is arg(2) == edit
easier to go
<?phpif (arg(1) == 'add') {
// new
}
else {
// edit
}
?>
Alan Davison
Back roads somewhere in South America
Workaround
I discovered a workaround (not a bug fix) to prevent non-authorized roles from editing the standard node Title field of certain content types:
1) install and enable the module "Automatic Nodetitles" (http://drupal.org/project/auto_nodetitle).
2) Add a CCK text field called "node_title" requiring (!) 1 (!) plain text (!) value.
3) Make sure that only admins have permission to edit and/or view aforementioned field (by default this should be like that).
4) Configure the "Automatic title generation"-section within the content type of your choice like so:
4.1) Check the radio-button: "Automatically generate the title and hide the title field", so the standard node Title field:
4.1.a) automatically copies the value from aforementioned CCK field upon saving (!) the node and
4.1.b) does not display on the node edit form.
4.2) Enter this PHP-pattern:
<?php return '[field_node_title-formatted]'; ?>4.3) Check this checkbox: "Evaluate PHP in pattern.".
5) For each node of the content type: edit the value of aformentioned CCK field and save the node.
BTW: This issue is also being discussed here: http://drupal.org/node/419458
Running Drupal 6.19 (or any newer stable version if available) with numerous modules for multi-sites.
subscribe
subscribe
Update?
Just wondering if there is an update for this? We have 2,500 groups using OG and want the groups to remain titled as we set them, to make sure that the url stays uniform
Mark C.