In this thread http://drupal.org/node/171249 a new option is discussed:
ANT will create the title but will not change the title once it is created.
This is usefull if the title has to be generated only once.

Comments

clivesj’s picture

Title:Add extra option to preserve title once created» Here is a patch for D7
Status:Active» Needs review
StatusFileSize
new4.41 KB

Here is a patch for D7.
It includes:
1. The new option "Preserve the title once it is created". This will have no effect on your other ANT nodes already in use.
2. Due to the extra option I changed the IF ELSE ELSIF to a SWITCH loop to prevent clutter
3 Added some description to the edit field on the node entry form so the user can see what is going on regarding the node title.

In the attached images on this node http://drupal.org/node/171249#comment-4033072 you can you see how it looks like.

klonos’s picture

That's great Clivesj!!!, thanx. ...but there might be cases where specific nodes might need a title change/correction. How about adding a way to override the auto-generated, to-be-preserved title. I was thinking something like:

1. A "Override to-be-preserved auto-generated node titles" permission that can be assigned only to specific roles/users.

2. A "Allow to-be-preserved titles to be overridden" checkbox in the "Automatic title generation options" fieldset that will be available/enabled only when the "Always auto-generate title but preserve first one" is selected. This will give users with the proper permissions the chance to be able to override auto-generated titles when/if required.

3. A "Override auto-generated title" button/checkbox in the node edit form that would make the title field selectable/editable again. If user enters custom text, that will be used. If they do click this "Override title" button and do not edit previous title, then a new title will be generated (à la old behavior).

What do you think?

PS: the title of this issue is to generic/vague for one to find. Also I do not understand why you started a new issue and did not post this over in #171249: Generate title only on insertion, not on update.

clivesj’s picture

Title:Here is a patch for D7» Generate title only on insertion, not on update (D7)

Ah, I forgot to fill in the title that´s why it came-up with "here is a patch for D7"
I didn't post the patch in the other thread since that is a D6 issue.
I will post the D6 patch there.

Do you (regulated by permission) want to be able to override all "ANT generated titles" whether they are preserved or not?
In this case we can add a button on the node entry form to enable this.
Maybe you want to exclude ANT title overriding for a certain node-type?

In any case I suggest to add the preserve option as per patch and start a new request for the override option. Let´s also hear Fago´s opinion on this.

klonos’s picture

I didn't post the patch in the other thread since that is a D6 issue...

Hmm... no it's not. You can switch it back to a 6.x issue (+ denote that in that issue's title with a "(D6)" similarly to what you did here), but I am afraid it's up to Wolfgang (a.k.a. fago, the module's maintainer) to decide how issues that require fixing in 7.x then backport to 6.x are handled. Usually developers like to keep their issue queue as clean (and short) as possible, so they do this in the same issue (usually 7.x first - 6.x after). That's why I asked in the first place, I don't actually mind either way.

... Maybe you want to exclude ANT title overriding for a certain node-type?

...yes, exactly. That's why I suggested (suggestion 3 in post #2 above) that there should be a checkbox to allow this in each content type's settings page. Perhaps I should have made it more clear that I meant that this should be a per-node setting.

btw... Thank you for your hard work and time spent in this one. I really appreciate it!

jmonkfish’s picture

The D7 patch seemed to be working at first, and then it stopped working and was acting like the "Enabled" mode.

I modified the code in two places and it works now:
Line 80-81 of the D7 patch ($node-> title == 'ant' changed to $node->title == 'ant')

-  return empty($node->auto_nodetitle_applied) && ($setting = auto_nodetitle_get_setting($node->type)) && !($setting == AUTO_NODETITLE_OPTIONAL && !empty($node->title));
+  return empty($node->auto_nodetitle_applied) && ($setting = auto_nodetitle_get_setting($node->type)) && !($setting == AUTO_NODETITLE_OPTIONAL && !empty($node->title)) && !($setting == AUTO_NODETITLE_ENABLED_PRESERVE && !($node-> title == 'ant'));

changed to

-  return empty($node->auto_nodetitle_applied) && ($setting = auto_nodetitle_get_setting($node->type)) && !($setting == AUTO_NODETITLE_OPTIONAL && !empty($node->title));
+  return empty($node->auto_nodetitle_applied) && ($setting = auto_nodetitle_get_setting($node->type)) && !($setting == AUTO_NODETITLE_OPTIONAL && !empty($node->title)) && !($setting == AUTO_NODETITLE_ENABLED_PRESERVE && !($node->title == 'ant'));

And I removed this from the patch because it was re-creating the title every time (Line 71-72):

-  if ($setting == AUTO_NODETITLE_ENABLED || ($setting == AUTO_NODETITLE_OPTIONAL && empty($form_state['values']['title']))) {
+  if ($setting == AUTO_NODETITLE_ENABLED || ($setting == AUTO_NODETITLE_OPTIONAL && empty($form_state['values']['title'])) || ($setting == AUTO_NODETITLE_ENABLED_PRESERVE)) {

It works great now!

nagiek’s picture

Is this code going to be merged into the -dev branch?

nodiac’s picture

Thanks for posting the diffs! If it works, I'll post it as a patch.

Spleshka’s picture

Thanks for your patch, but it breaks logic for other node titles. I attached a patch that works for me.

nfriend’s picture

Great module and nice patch - just what was needed!

#8 worked for me but only after implementing the last changes mentioned in #5 "And I removed this from the patch because it was re-creating the title every time (Line 71-72):"

The first change mentioned in # 5 is in the #8 patch.

Thanks to all!

Neil

klonos’s picture

#8 worked for me but only after implementing the last changes mentioned in #5... The first change mentioned in # 5 is in the #8 patch.

The patch in #8 contains that change too (lines 56-59).

nfriend’s picture

Hey Klonos - in response to #10 - Actually those lines (56-59 in #8) (71-72 in #5) , put in what number 5 says to leave out. So I removed them.

I did the #8 patch first in full but still had it being recreated each time. I saw the # 5 note, and removed the 56-59 insertion, leaving the original and it works!

At least for me.

Thanks for your help.

Neil

klonos’s picture

ok, thanx.

alimbert’s picture

When I remove line 56-59 I get a malformed function. Can anyone verify the exact code that needs to be moved. Line 56-59 in my patch looks like this:

56 - if ($setting == AUTO_NODETITLE_ENABLED || ($setting == AUTO_NODETITLE_OPTIONAL && empty($form_state['values']['title']))) {
57 + if ($setting == AUTO_NODETITLE_ENABLED || ($setting == AUTO_NODETITLE_OPTIONAL && empty($form_state['values']['title'])) ||
58 + $setting == AUTO_NODETITLE_ENABLED_PRESERVE) {
59 auto_nodetitle_set_title($node);

clivesj’s picture

I'm willing to make a definate patch based on latest dev. But I think fago has to indicate wheter he is willing to incorporate the change. I 'm also willing to co-maintain the module. But i think it will becomd mess if we all propose changes witthout being able to merge ghem into ghe project and have them tested by the community.
I think this change enhances the modules functionality.

Edit: typo's, still have to get used to typing on a smartphone :)

jzornig’s picture

Would be nice to have. My 2c.

juves’s picture

This feature is still not implemented in dev, can somebody please post a final patch?

clivesj’s picture

@juves. I don't think the module maintainer wants to further develop this module. I think the intention is to switch over to:
https://drupal.org/project/auto_entitylabel

lostchord’s picture

Issue summary:View changes

@clivejs. I'm not sure that this module solves the problem. The screen shot does not show an option to persist the original title.

@juves. The workaround I'm using is to bring the field_default_token module into the picture and create fields on the form that the user can view but cannot write using field level access control - during node creation these fields are not visible. I set the default value for these fields to be the values of the tokens I'm using in the title and then use the field values as the replacement tokens in the title. Seems to work because the value is persisted in the database rather than the token placeholder. View access for the user seems to be required. I'm not sure if this works for all possible atomic field types.

Update.
There are some race condition issues with at least Term References where the values stored as the default values in fields on the form are not picked up on the create but are picked up on subsequent edits. The raw values on the original fields on the form are picked up on the initial save so this is not a major issue.

Amir Simantov’s picture

Hi guys, thanks for this issue. I wanted to do the same but to let an authorized user to DO edit the title manually or to call for computing. I do not need it in the interface, so some code is enough in this case of mine. I am writing it down here both for sharing and for revision.

<?php
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  switch (
$form_id){
    case
'print_node_form':
   
// Prevent changing of the title (once set) to anyone except an authorized user.
    // By not rendering the title to other users, the title is not empty (afer first created) and
    // therefore they cannot change it.
   
$form['title']['#access'] = user_access('administer nodes');

    break;
  }
}
?>