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.
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.
/**
* 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';
}
}
}
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
$form['title']['#access'] = user_access('administer node titles');
}
}
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.
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
$form['title']['#access'] = FALSE;
}
}
This will eliminate all title fields from showing in the CMS.
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 #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
Thanks for the code. I implemented this in Drupal 7 using hook_permission() instead of hook_perm(). Also targeted a specific content type by adding "&& $form['#node']->type == "MYCONTENTTYPE")". Here it is in full...
function MYMODULE_permission() {
return array(
'administer node titles' => array(
'title' => t('Administer node titles'),
'description' => t('Perform administration of node titles.'),
),
);
}
function MYMODULE_form_alter(&$form, $form_state, $form_id) {
// Check that the form is a content type edit/create form and that node is of type "core_condition"
if (isset($form['#node']) && $form['#node']->type .'_node_form' == $form_id && $form['#node']->type == "MYCONTENTTYPE") {
// If they do not have the title permission, hide the title field
$form['title']['#access'] = user_access('administer node titles');
}
}
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 :-)
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.
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?
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.
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
============
Drupal Core Maintainer for "Out of the Box" Initiative.
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:
I haven't tested/run this code, but it should guide you towards what you require.
Alan Davison
www.caignwebs.com.au
Alan Davison
Build your own module and use hook alter
This could prevent anyone to modify title value.
correction
----
Sudo Kill Cylons
Use #access FAPI property
Even better :)
Alan Davison
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 :)
This will eliminate all title fields from showing in the CMS.
Alan Davison
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
Thanks
Thanks for the code. I implemented this in Drupal 7 using hook_permission() instead of hook_perm(). Also targeted a specific content type by adding "&& $form['#node']->type == "MYCONTENTTYPE")". Here it is in full...
same thing but for taxonomy terms
I printed out $form and looked through it and modefied the code to match my needs:
This was very helpful
Thank you
Casey Carnnia (carnnia@gmail.com)
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
Alan Davison
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
That just saved me a lot of
That just saved me a lot of hassle. Awesome workaround. Thanks.
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
============
Drupal Core Maintainer for "Out of the Box" Initiative.
Take a look at
Take a look at http://drupal.org/node/419458#comment-7069916, may be useful for simple needs on Drupal 6.