PDA

View Full Version : Using a vbulletin variable as the default for a setting in XML file


MarkFL
04-08-2015, 05:27 PM
Hello,

I am working on modifying a product I wrote, and for the product's option settings in the AdminCP, I want to present the user with radio buttons to select a forum, rather than having to enter the forumid manually. This I have working, however, I want the default value to be the forum that has been chosen to receive user-reporting of posts.

Here is my code for the setting:

<setting varname="markfl_par_report_forumid" displayorder="35">
<optioncode><![CDATA[" . eval('$options = "";
foreach($vbulletin->forumcache AS $forumid => $forum)
{
if ($forum[parentid] > 0)
{
$options .= "\\t\\t<label for=\\"setting[$setting[varname]]$forumid\\" title=\\"forumid: $forumid\\"><input type=\\"radio\\" tabindex=\\"1\\" name=\\"setting[$setting[varname]]"."[]\\" id=\\"setting[$setting[varname]]$forumid\\" value=\\"$forumid\\"" . iif(strpos(",$setting[value],", ",$forumid,") !== false, \' checked="checked"\') . iif($vbulletin->debug, " title=\\"name=&quot;setting[$setting[varname]]&quot;\\"") . " />$forum[title]</label><br />\\n";
}
}
return "<span class=\\"smallfont\\">\\n$options\\t</span>";') . "<input type=\"hidden\" name=\"setting[$setting[varname]][]\" value=\"-1\" />]]>
</optioncode>
<datatype>free</datatype>
<defaultvalue><![CDATA[" . eval('return $vbulletin->options[\'rpforumid\'];') . "]]></defaultvalue>
</setting>


The code in red is what's not working, and I would like to know what I need there. :D

kh99
04-08-2015, 05:42 PM
I'm not 100% sure, but I think the defaultvalue in the xml is only used at the time the product is actually being installed, and I don't think you can put code there. Maybe what you want is to include some install code that sets the initial value of your option by reading the other option?

kh99
04-08-2015, 06:01 PM
...but it looks like it's a bit complicated bcause when the install code is run, the settings haven't been created yet. So I think what you want to do is set
$arr['options']['settinggroup']['groupname']['setting']['settingname']['defaultvalue']

where groupname and settingname are replaced by the actual group and setting varnames.

MarkFL
04-09-2015, 02:47 PM
I wasn't able to get this to work, so what I decided to do as a workaround is if the user does not select a forum, then the report forum is used as the default. Perhaps I can get the report forum to be checked by default for a future update.