Drupal and Taxonomy Weights

I recently worked on a project in Drupal that called for a large number of taxonomy terms. I needed to put the terms in a specific order, but unfortunately, I had more terms than Drupal's weight field supports, which is a range from -10 to +10.

I did a quick search on Drupal, and was horrified to see how many people are hacking core to add a greater range. This is pretty easy to do without hacking core. All you need to do is create your own module that implements hook_form_alter().

my_module.module

<?php

function my_module_form_alter($form_id, &$form) {
  switch(
$form_id) {
    case 
'taxonomy_form_term':
    
$form['weight']['#delta'] = 100;
    break;
  }
}
?>

And that's it!

[tags]alter, drupal, form, hook, module, taxonomy, term, weight[/tags]

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Drupal 5 or 6

I tried this as a d6 module. The modules page says that the module is incompatible with 6.2
Is this designed as a d5 module - how would it need to be updated for d6?

I have a big 800 word vocab list that needs to be weighted and/or displayed hierarchically with $terms

there are few if any d6 solutions for this in contrib modules
there is a core patch > but never patch core is the mantra

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

About Erich

Erich is a web developer and a native New Englander who is passionate about life, the universe, and everything.

He is a Drupal consultant, previously employed as a senior developer at Harvard University, working on the IQSS OpenScholar project.  Prior to joining the team at Harvard, he was the engineering manager at CommonPlaces e-Solutions, in Hampstead, NH, contributing as the lead engineer on the Greenopolis.com and Twolia.com.

Erich is active in the Drupal community, having contributed modules and patches to the community. He presented at DrupalCon in Szeged Hungary, and co-presented at DrupalCon 2009 in Washington, DC.

Erich lives in New Hampshire with his wife, two sons, and three weimaraners.  When not writing code, Erich enjoys landscaping and woodworking.

Faceted search

Categories

Content type

Project types

Artwork Type

Artwork Tags

Recent comments

Activity Stream

August 29, 2011

August 25, 2011

August 24, 2011

August 23, 2011

August 15, 2011

August 11, 2011

August 10, 2011

August 9, 2011

August 4, 2011

August 3, 2011