I have been looking around the site trying to figure out why the node title is limited to 128 characters, but have been unable to find an answer. Is there a technical reason for this limit or is this done for cosmetic purposes?
This question might sound odd, but users on one of the sites that I administer are not happy about this limit, and are also not happy with the response that that is just the way things are. Although I am not to impressed with titles longer than 128 characters, I do understand the users frustration of not being able to use their long titles merely because I think that it is unnecessary and does not look good.
This basically leaves me with two options. Either I find a technical reason for this limit, or I need to patch the drupal code to accept longer titles. I would obviously like to avoid going the second route, as I would be messing with drupal's core, which in turn has serious implications on upgrading drupal to keep up to date.
Thanks in advance for any answers.
Comments
First, modify the two
First, modify the two database tables, 'node' and 'node_revisios', to have their 'title' field longer (it's fixed on 128 chars now). You can do this with, e.g., phpMyAdmin.
Then, locate the $form['title'] line in all node modules (e.g., 'story.module', 'page.module') and add an '#maxlength' attribute, because the default is 128. You can do this with any text editor.
That is, change any:
to:
I don't have time to check that, but I believe these two steps is all you have to do.
(BTW, it seems that the title for comments is limited to 64 chars...)
I understand where the limit
I understand where the limit gets enforced, I am still unsure however why this limit is in place. I am hoping that there is a technical reason for this hard limit, so that I can give a solid reason to the users.
In general I prefer to avoid modifying the core drupal code, as this adds to the maintenance overhead when upgrading. It also has the potential to introduce unforeseen bugs as I might modify behavior that a downstream module developer might rely on. Although in this case that seems unlikely.
I understand where the limit
That's because programmers love powers of two (2, 4, 8, 16, 32, 64, 128, 256).
128 is a power of two. 256 looks way too long, so they chose 128. Nothing very special about it.
There's a much better solution than the one I've shown earlier: to write a tiny module that implements hook_form_alter(). And if you put this module in your /sites/ directory you can even forget about it. Of course, you still have to modify the database structure.
I can't imagine a scenario where lengthening the title field would break something.
Thanks for the tip amnon.
Thanks for the tip amnon. Using the hook to override the title limit is the perfect solution; both me and my users can live happily ever after :)
Did you end up writing that
Did you end up writing that module? If so, could you post it here?
Thanks.
Module to change maxlength of form field using hook_form_alter
I created a module to do this with the help of the drupal dojo notes here: http://groups.drupal.org/node/4308
It was written for drupal 4.7 and increases the maxlength of 2 autocomplete node_reference fields (in my case these fields were called field_reference_publication and field_event_reference respectively), and the title field's maxlength for all forms:
('my_maxlength' is the name of my module and this function goes in the module my_maxlength.module)
Charles
www.parkroad.co.za
Charles
Drupal development, Cape Town, South Africa
Worked great!
I just put this in place on our site and it worked great. I wonder if it's worth it to try putting the 'alter table' statements in so that by installing the module it alters the DB as well? I'm guessing no, but here's what I used:
ALTER TABLE `node` CHANGE `title` `title` VARCHAR( 255 ) CHARACTER NOT NULL
ALTER TABLE `node_revisions` CHANGE `title` `title` VARCHAR( 255 ) CHARACTER NOT NULL
Thanks -
Jason
Should this work with Drupal 5.x?
Hi!
Thanks for the tip. I just tried adding this snippet to my 5.x installation but still get the 128 limit error message. The module is enabled. Is there anything else I need to do to make this hook get activated?
Thanks, Nic.
-- festina lente
256 char limit
Interesting - I am able to increase my title field to 255, but at 256 I get this error:
ERROR
MySQL said: #1170 - BLOB/TEXT column 'title' used in key specification without a key length
...
Don't use 256. The title, as almost all string fields, is stored as a VARCHAR type. These are limited to 255 chars. When you use greater lengths, MySQL implicitly turns them into the TEXT type, which is a bit less efficient. Only a portion of a TEXT field can serve in a key/index, and since the length of this portion isn't specified in the Drupal definition of the 'node' table, MySQL complains.
(The 255 limitation was lifted in MySQL 6.)
MySQL 5.0.3
You probably meant MySQL 5.0.3: that's when the VARCHAR limit went from 255 to 65,535.
Incredibly enough my titles are sometimes longer than 255 characters! I know, that's a long read, but that's the way French law titles are...
Drupal 6.3 only goes up to 255 chars so I'll probably need to do some custom work as well.
I am not sure if it is
I am not sure if it is useful for you, but on drupal 5.x I just followed the suggestions above and manage to get 300 chars for node and node_revision titles. Everything works fine: does it exist a specific limitation in 6.3?
http://drupal.org/project/lon
http://drupal.org/project/longer_titles