I'm facing a problem with commerce product title length. I want to increase the lenght over 255. What I've tried so far is:

  • Change DB field from varchar to text

  • Change the maxlength of the form field

  • Change the formfield to a textarea

Any of the form changes lead to an error. Any idea how to increase the length?

2 Answers 2


I wouldn't increase the length of the field, but instead ask yourself why you are storing so much information in the title. There is a very good chance you simply need to split the information out into different fields or use a textarea to store ancillary information. You don't know how many assumptions commerce makes about the title field with regards to logic and formatting and the general Commerce wisdom is to not mess with the internals.

  • My problem is, that I can't decide that. A customer said he needs more than 255 characters in the title and so I have to give him what he wants. I know that messing with the core isn't a good idea, but I really have to. Maybe I could hide the title field, create a new textfield, and copy 255 characters from that to the title.
    – Andi
    Apr 10, 2015 at 15:00
  • It sounds like the issue lies more with your client. What are some examples of titles the client is creating? Can any of that information be stored in a more semantic field? What is the reasoning behind using the title? Titles to me are meant to be a very concise summary of what is being purchased and when you step outside of that concept, you are probably breaking commerce in other areas.
    – Sam Becker
    Apr 10, 2015 at 15:04
  • They do store to much information in the title which could easily be split up, but as they had a system with one gigantic title field before the new one, they just want it the same way. I tried my best to convince them to split up, but there seems to be no chance that they'll do that.
    – Andi
    Apr 10, 2015 at 15:07
  • I would explain the benefits of storing things correctly, that is: searchability, filtering, reporting, future-proofing, design, semantic HTML, rich snippets and validation to name a few. Beyond that, you need to question why a client wouldn't take your recommendation on something which is probably easier than what they are used to and consider not working with the client. If ease of use is the issue, perhaps tools could be developed to take their long string input and transform it into various fields with semantic meaning.
    – Sam Becker
    Apr 10, 2015 at 15:14

Sam's answer and comments should be taken as the best advice for this, but as a technical exercise it shouldn't be too difficult:

// Alter the schema
function MYMODULE_schema_alter(&$schema) {
  $schema['commerce_product']['fields']['title']['length'] = 512;
  $schema['commerce_product_revision']['fields']['title']['length'] = 512;

// Change the DB in an update hook
function MYMODULE_update_7100() {
  $schema = drupal_get_schema_unprocessed('commerce_product');

  $new_field = array('length' => 512) + $schema['commerce_product']['fields']['title'];
  db_change_field('commerce_product', 'title', 'title', $new_field);

  $new_field = array('length' => 512) + $schema['commerce_product_revision']['fields']['title'];
  db_change_field('commerce_product_revision', 'title', 'title', $new_field);

// Change the form
function MYMODULE_form_commerce_product_product_form_alter(&$form, &$form_state, $form_id) {
  $form['title']['#maxlength'] = 512;

Completely untested, use with caution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.