<a href="http://drupal.org/node/72577">http://drupal.org/node/72577</a><br>
<div class="content"><p>Man this is driving me nuts. Here's my logic, tell me if it's wrong:</p>
<div class="codeblock"><code><font color="#000000"><font color="#0000bb">&lt;?php<br> $form</font><font color="#007700">[</font><font color="#dd0000">'autorole_settings'</font><font color="#007700">] = array(</font><font color="#dd0000">
'#type' </font><font color="#007700">=&gt; </font><font color="#dd0000">'checkboxes'</font><font color="#007700">, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font><font color="#dd0000">'#title' </font><font color="#007700">=&gt; </font><font color="#0000bb">t</font><font color="#007700">(</font><font color="#dd0000">'Vocabularies to auto-generate roles for'</font><font color="#007700">
),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; </font><font color="#dd0000">'#default_value' </font><font color="#007700">=&gt; </font><font color="#0000bb">variable_get</font><font color="#007700">(</font><font color="#dd0000">
'autorole_settings'</font><font color="#007700">, </font><font color="#0000bb">0</font><font color="#007700">),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; </font><font color="#dd0000">'#options' </font><font color="#007700">=&gt; 
</font><font color="#0000bb">$vocabularies</font><font color="#007700">,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; </font><font color="#dd0000">'#description' </font><font color="#007700">=&gt; </font><font color="#0000bb">t</font>
<font color="#007700">(</font><font color="#dd0000">'Which vocabularies to auto-generate roles for'</font><font color="#007700">))<br></font><font color="#0000bb">?&gt;</font></font></code></div>
<p>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
=&gt; value pairs, which are all integers.</p>
<p>I get this vaiable with a call to variable_get('autorole_settings', 0), which should return the serialized data.<br>
I then unserialize the data which (for the serialized data above,) should give me an array like so:</p>
<p>$unserialized = array(3 =&gt; 3, 2 =&gt; 0, 1 =&gt; 0);</p>
<p>Now, I should be able to iterate over that array with foreach. </p>
<div class="codeblock"><code><font color="#000000"><font color="#0000bb">&lt;?php<br> </font><font color="#007700">foreach(</font><font color="#0000bb">$unserialized </font><font color="#007700">as </font><font color="#0000bb">
$vocab </font><font color="#007700">=&gt; </font><font color="#0000bb">$option</font><font color="#007700">) {<br>&nbsp; &nbsp;  </font><font color="#ff8000">//if an options value is zero, it is not selected<br>&nbsp; &nbsp; &nbsp; &nbsp;  </font><font color="#007700">
if(</font><font color="#0000bb">$option </font><font color="#007700">!= </font><font color="#0000bb">0</font><font color="#007700">) {<br>&nbsp; &nbsp; &nbsp; &nbsp;  </font><font color="#0000bb">$terms</font><font color="#007700">[] = </font>
<font color="#0000bb">module_invoke</font><font color="#007700">(</font><font color="#dd0000">'taxonomy'</font><font color="#007700">,</font><font color="#dd0000">'get_tree'</font><font color="#007700">, </font><font color="#0000bb">
$vocab</font><font color="#007700">);<br>&nbsp; &nbsp;  }<br> }<br></font><font color="#0000bb">?&gt;</font></font></code></div>
<p>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.</p>
<p>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</p>
<div class="codeblock"><code><font color="#000000"><font color="#0000bb">&lt;?php<br> </font><font color="#007700">if(</font><font color="#0000bb">$field</font><font color="#007700">-&gt;</font><font color="#0000bb">type 
</font><font color="#007700">== </font><font color="#dd0000">'vocabulary' </font><font color="#007700">&amp;&amp; </font><font color="#0000bb">in_array</font><font color="#007700">(</font><font color="#0000bb">$field</font>
<font color="#007700">-&gt;</font><font color="#0000bb">title</font><font color="#007700">, </font><font color="#0000bb">$terms</font><font color="#007700">))<br></font><font color="#0000bb">?&gt;</font></font></code></div>

<p>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?</p>
</div>
<br>
<br>