I have a couple of modifications I did to the Drupal core:

  • search module: I added a class to the <ul> that contains the "no-results" text.
  • image module: I changed the 'title' attribute to have a #maxlength of 500 for a specific content type, so that only nodes of that type can have a longer 'title'

The question is: how would I do that without modifying the Drupal core? Is there a way of overriding those default outputs in a custom module? I'm looking for a way of doing that without touching the core, or to confirm that a modification in the core was the only feasible way.

  • The second one seems like a hook_form_alter(). Also You added a class to the what that contains the no-results text? – beth Jan 30 '13 at 16:14
  • @beth to the <ul>, sorry, I edited the text and it appears now – jpatiaga Jan 30 '13 at 16:22

I'm not sure how the second one is Image module-specific, but you would override that maxlength like so:

function hook_form_[content-type]_node_form_alter(&$form, &$form_state, $form_id) {
    $form['title']['#maxlength'] = 500;

... where 'hook' is replaced with the name of your custom module, and [content-type] is the machine name of your content type.

The API function is hook_form_FORM_ID_alter()

For the search form theming, you probably want something like template_preprocess_search_results() in your template.php of your custom theme, and/or adding a custom search result template to the theme's templates folder.

Oh, and in case it needs saying again,



Definitely don't hack core. With the search module there are several .tpls in the module that you can copy to your theme folder and customize.

Regarding your image module changes, that would be done via a form_alter in a custom module. It is worth the extra effort to learn it the "right way" because that is how you can maintain an upgrade path which is very important.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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