Man this is driving me nuts. Here's my logic, tell me if it's wrong: <?php $form['autorole_settings'] = array('#type' => 'checkboxes', '#title' => t('Vocabularies to auto-generate roles for'), '#default_value' => variable_get( 'autorole_settings', 0), '#options' => $vocabularies, '#description' => t('Which vocabularies to auto-generate roles for')) ?>
Is in the _settings hook. This means that when someone goes and changes this, it gets stored in the variabe database table. It is. It is stored as serialized data in the form a3;{i:3;i:3;i:2;i:0;i:1;i:0;}, which means that it is an array with three elements - then the key => value pairs, which are all integers.
I get this vaiable with a call to variable_get('autorole_settings', 0), which should return the serialized data. I then unserialize the data which (for the serialized data above,) should give me an array like so:
$unserialized = array(3 => 3, 2 => 0, 1 => 0);
Now, I should be able to iterate over that array with foreach. <?php foreach($unserialized as $vocab => $option) { //if an options value is zero, it is not selected if($option != 0) { $terms[] = module_invoke('taxonomy','get_tree', $vocab); } } ?>
Since the options in the form were generated by a call to taxonomy_get_vocabularies, $vocab in the foreach call should correspond to the vocabularie's vid. - so I can populate the variable $terms with the term data through the call to taxonomy_get_tree. Now I should have a list of terms that are contained within the vocabularies that were selected to be used.
The part that assigns the roles is called by profile.module in the profile_save_profile function. My module checks to see if it's a vocabulary (which I'll be moving that into profile, probably....but anyhow), and then checks to make sure that the field title - which is the name of the term, is a member of terms with <?php if($field->type == 'vocabulary' && in_array($field->title, $terms)) ?>
Now, I can not for the life of me figure out why it is that if I select one vocabulary, it assigns roles for all vocabularies. The data in the variable table is correct, and as far as I can tell, the logic is as well. Maybe I need to run it through a debugger and trace it....any suggestions? On what's going on, or a good tracer, or anything?