Closed (fixed)
Project:
Automatic Nodetitles
Version:
7.x-1.0-alpha1
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Anonymous (not verified)
Created:
8 Sep 2008 at 01:35 UTC
Updated:
16 May 2024 at 00:49 UTC
Jump to comment: Most recent
Comments
Comment #1
no2e commented(Subscribe)
I just created a forum topic about that topic, before I read this issue: http://drupal.org/node/305328
Comment #2
Anonymous (not verified) commentedI found one way to do it...
I put the following code in the pattern for my auto nodetitle (set to PHP obviously):
It counts the number of nodes of a given type (node_type) and adds some leading 0's to it.
The only problem is that it doesn't count deleted nodes (i.e. if you have 15 nodes (the last of which has a title of '015') and you delete a node, the next one you create will be given the title of '015'...) This may or may not be ideal for certain situations, in my case I'll just stop users from deleting nodes.
Hope this helps!
EDIT: Oops, changed the sprintf function to increment the number so if there are 15 existing nodes, the new one will be titled '016' :)
Comment #3
Anonymous (not verified) commentedJust came across another problem...
When you edit an existing node, the PHP is run again and the number changes.
Any ideas how to stop this happening?
Comment #4
asak commentedcould this be the answer?
Actually, seems that this is the answer...
Comment #5
Anonymous (not verified) commentedI actually just ended up using the Workflow-NG module to run the PHP code whenever a node of a particular type was created. This stops it running after being edited.
Comment #6
asak commentedBWPanda: My problem is that nodes on my site are often deleted.... and as you mentioned in comment #2 this will be a problem...
Thank you!
Comment #7
potss commentedComment #8
asak commented@potss - that's an interesting one...!
Comment #9
Anonymous (not verified) commentedClosing.
Comment #10
hgurol commentedWhen I use the potss on #7, I keep getting HTTP 500 errors when saving a node.
Is there any working code snippets that I can use for D7?
...or is there any better way to use Auto Nodetitles to make the Title field work as a primary key column with auto increment ?
(maybe I should open a new issue for the last sentence)
Thanks...
Comment #11
lightstring commentedSubscribing
Comment #12
Zuzuesque commentedCode from above transformed to work with Drupal 7. Works on my system.
However I still see a problem with the code... its not atomic. A problem if you want truely unique titles, somewhat okay if you don't. Not really pleased with the solution as of yet.
Comment #13
Anonymous (not verified) commentedHere's the code I just used on a D7 site, if anyone's interested. It's got some comments explaining the different parts, and it works for both creating new nodes and updating the title of existing ones, but is otherwise pretty much the same as above.
I used this module and the PHP filter from core.