0
votes

I wanted to perform a quick alteration of ubercart form data (I want to remove links to product nodes in the shopping-cart). I found a solution that involves implementing hook_form_alter() by creating a new module (link and code below).

My question is, do I have to make a new module or can I just add this function into my theme's template.php file? I tried the later but I couldnt get it to work (I renamed the function to theNameOfMyTheme_form_alter).

(The bigger issue here is me trying to get my head round all this drupal 6 override stuff. Eg if I come across some code that I want to alter, how can you tell if you are supposed to create a module or change your theme?).

http://www.ubercart.org/forum/support/2298/remove_product_links_shopping_cart

function your_module_form_alter(&$form, &$form_state, $form_id) {
  if($form_id == 'uc_cart_view_form') {
    foreach($form['items'] as $key => $item) {
      if(!empty($item['desc']['#value'])) {
        $form['items'][$key]['desc']['#value'] = strip_tags($item['desc']['#value']);
      }
    }
  }
}
2

2 Answers

4
votes

Adding to Clive's solution, just to confirm for anyone else looking for this: hook_form_alter isn't called for themes in Drupal 6.

3
votes

hook_form_alter() is one of the hooks that's invoked for both themes and modules so putting it in your template.php file is fine.

It's actually documented to that effect on the version of the function for Drupal 7, but I guess they missed it on the Drupal 6 version.

Remember to clear Drupal's cache once you've added the hook so it gets picked up.