I have 20 "action" fields and need a taxonomy term list of those actions. I installed the module and created the node with the actions. Now I go into each of those 20 fields and select the taxonomy. It creates a key/value pair and then dumps them in the same place where I would have to type them manually. But what happens now if I want to add another action term? Will it automatically appear on all 20 fields? Or every time I create a new term, I have to manually update the webform? Without it being dynamic, it really doesn't work for keeping up with taxonomy terms. If I have to go in and update every field and only add one term at a time, I might as well just type them in.

Comments

steveoliver’s picture

It looks like it is dynamic. Have you tried it yet?

flightrisk’s picture

Hmmmm. I did try it, but I didn't look in the right place. I added a taxonomy term, then went to "find content" and found my node with the webform attached to it. I then clicked on edit and went to the tab/button at the top of my admin screen to "webform". I scrolled down to the fields that have a taxonomy list and looked at the options item and saw the value/key pairs that it added when I selected the taxonomy term from the list and it is NOT there. But if I go to the actual webform as if I am going to create a new submission, when I look in the dropdown for my available terms, it IS there. Go figure. Thanks for making me check again. I'll report this discrepancy.

steveoliver’s picture

That's what this - http://drupal.org/node/767290#comment-5361876 - was about

codecouleurs’s picture

Hi,

The "webform_component" table (field "extra") is not updated when we add/update/delete some terms in the vocabulary used in pre-built options. When the webform is built it doesn't take the options in the database so this is not a problem.
But I use "webform2pdf" module which proposes some tokens to list all options of a component and highlights those which has been checked. And "webform2pdf" module does used the database to built its tokens.

So I have added 3 functions in webform_term_opts.module to update the database when we add/update/delete some terms (this code may need review).

/* hook_taxonomy_term_insert() */
function webform_term_opts_taxonomy_term_insert($term) { 
   $query = db_select('webform_component');
   $query -> fields('webform_component', array('cid', 'extra'));
   $query -> condition('extra', "%vid_".$term->vid."%", 'LIKE');
   $result = $query -> execute();
   
   foreach($result as $record) {
        $data = unserialize($record->extra);
       
        $data['items'] .= 'tid_'.$term->tid.'|'.$term->name."\n";
        $final_data = serialize($data);
        
        $query = db_update('webform_component');
        $query -> fields(array('extra' => $final_data));
        $query -> condition('cid', $record->cid);
        $result = $query -> execute();     
    }
}

/* hook_taxonomy_term_update() */
function webform_term_opts_taxonomy_term_update($term) {
   $query = db_select('webform_component');
   $query -> fields('webform_component', array('cid', 'extra'));
   $query -> condition('extra', "%vid_".$term->vid."%", 'LIKE');
   $result = $query -> execute();
   
   foreach($result as $record) {
        $data = unserialize($record->extra);
        $data['items'] = str_replace('tid_'.$term->tid.'|'.$term->original->name, 'tid_'.$term->tid.'|'.$term->name,  $data['items']);
        $final_data = serialize($data);
      
        $query = db_update('webform_component');
        $query -> fields(array('extra' => $final_data));
        $query -> condition('cid', $record->cid);
        $result = $query -> execute();     
    }
}

/* hook_taxonomy_term_delete() */
function webform_term_opts_taxonomy_term_delete($term) {
   $query = db_select('webform_component');
   $query -> fields('webform_component', array('cid', 'extra'));
   $query -> condition('extra', "%vid_".$term->vid."%", 'LIKE');
   $result = $query -> execute();
   
   foreach($result as $record) {
        $data = unserialize($record->extra);
        $data['items'] = str_replace('tid_'.$term->tid.'|'.$term->name."\n", '', $data['items']);
        $final_data = serialize($data);
        
        $query = db_update('webform_component');
        $query -> fields(array('extra' => $final_data));
        $query -> condition('cid', $record->cid);
        $result = $query -> execute();     
    }
}