Limited number of terms for a node

cirotix - April 4, 2006 - 15:05

Greetings:

I am building a portal for a scientific community and I am using the categories to assign keywords to the contributions (such as Physical Model, Sound Synthesis, Music Information Retrival,...) I am also using the categories to classified the contributions within different types such as: conference, workshop, call, annoucement,... It seems that the number of terms that can be attributed to a node is limited so that I can have only a maximum number of keywords for each contribution.

Is it an hard limitiation or is it configuration problem? Is there any way to overcome this limitation?

thank you for your help. By the way, Drupal is really great, I wish I had discovered it sooner (I was using Mambo before...)

It's not configurable off the bat

adrian - April 4, 2006 - 15:49

but i think you will be able to write some simple validation code to do it. (this is only in Drupal 4.7. I'm not sure it's practical / easy to do it in 4.6)

<?php
function mymodule_form_alter($form_id, &$form) {
   if (
$form['type']) {
     if (
$form['type']['#value'] . '_node_form' == $form_id) {
      
$form['#validate']['mymodule_validate_max_terms'] = array(1 => 4); // where 1 is the vocabulary id, and 4 is the maximum terms.
    
}
  }
}

function
mymodule_validate_max_terms($form_id, $edit, $vocabs) {
    foreach ((array)
$vocabs as $vid => $max) {
      if (
sizeof($edit['taxonomy'][$vid]) > $max) {
       
form_set_error($edit['taxonomy'][$vid], t('too many terms'));
      }
   }
}
?>

Tags will work differently though.

--
The future is so Bryght, I have to wear shades.

Thanks adrian for your reply

cirotix - April 4, 2006 - 16:08

Thanks adrian for your reply but I think that I didn't explain my problem correctly.

For now it seems that there is maximum number of terms within a vocabulary that can be attached to a node. I have forgotten to say that I am using free taggings so users can add the keywords (=terms) they want.

Actually I don't want to have any limitation on the number of keywords a user can attach to his node. For now there is a limitiation which is pretty low (I can check it and submit it here).

To make an exemple:
Let say that I have a post that deals which sound synthesis. I want to add the following keywords:

Sound Synthesis, Physical Model, Gestural Control, Karplus-strong, Piano, String, Expressivity, feature-driven audio-synthesis.

Drupal won't let me insert the last part of my keywords and will stop at feat (in the last keywords). Therefore it seems to me that there is a max size for the size of the string that hold the terms attached to node.

oh that's simple too

adrian - April 4, 2006 - 17:52

The text field has a maxlength, which you can change using the same mechanism.

--
The future is so Bryght, I have to wear shades.

Thanks again

cirotix - April 5, 2006 - 13:52

I have changed the default value in taxonomy.module (line 641 for those who are interested) from 100 to 300. IMO 100 is a little bit low, espcially for websiste which needs a lot of keywords for a node. Maybe the maxlenght should be configurable in the admin interface.

I'd like to do just the

Briang - May 12, 2006 - 06:49

I'd like to do just the opposite. I think it would be nice to be able to limit the number of terms used, instead of the number of charactors in the text box. For site with a lot of user participation, it would be good to limit the number of tags they are allowed to add. This way they could not spam the site by adding many unrelated key words to their content.

_
http://catholicmusiczine.com

New module I would like you to test

codexmas - July 13, 2006 - 01:11

Hey there, I just wrote this module today as I needed to scratch the same itch...

It isn't yet available as a tarball, should be soon.
You can download it via the CVS repo online:
http://cvs.drupal.org/viewcvs/drupal/contributions/modules/taxonomy_limit/

Please try it out and see if works are you expect, or needs additional functionality.

 
 

Drupal is a registered trademark of Dries Buytaert.