1

Currently the search field has a maxlength of 128, I am wondering if there is any way to increase it too maybe 255?

3
  • 3
    Have you tried using hook_form_alter and changing the #size property of the textfield? api.drupal.org/api/drupal/…
    – rwaery
    Commented Aug 27, 2014 at 17:38
  • (#maxlength, not #size)
    – Clive
    Commented Aug 27, 2014 at 17:56
  • From what I can tell, only the Search Field in the Search Block has a limit of 128 characters. The field in the form at the top of the search results page has a limit of 255 already. Interesting. That makes me think that this would be as simple as using hook_form_alter() to increase #maxlength as @Clive and @rwaery have suggested. Commented Aug 27, 2014 at 20:15

1 Answer 1

0

Yes but it's not pretty. Drupal really doesn't want you to change field definitions after they've been created.

The correct way would be to create a new field definition and migrate values from the old field into the new one.

The quick and dirty way would be to manually change the field definition in the database directly.

The quick and dirty way that is deployable via code is to do a two-step process:

  1. Export the field (such as with Features) and alter the #maxlength setting in the code.
  2. TEMPORARILY hack core by commenting out the code in hook_field_update_forbid() in field.api.php.
  3. Deploy a tag containing 1 and 2. Run updates.
  4. UNCOMMENT hook_field_update_forbid and deploy that tag so further changes are not allowed and core is put back in its natural state.

This is terrible but I have done it and it works.

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.