I am creating a custom Preferences tab with a checkbox, and it's ALMOST
working. I'm sure I'm missing something simple... any guidance?
The behavior is:
* The new tab appears
* It contains a checkbox, "Test checkbox"
* When I click "Save" for the first time, the value gets properly
saved in the database, with a value of zero
* When I toggle the checkbox and Save again, the value "1" is
properly written to the database
* BUT..... the value remains "1" in the database, no matter what
else I do: toggling, saving, etc.
Here is the very short code:
$wgMyFunkyPreferences = new MyFunkyPreferences();
class MyFunkyPreferences {
public function __construct() {
global $wgHooks;
$wgHooks['RenderPreferencesForm'][] = array($this, 'render');
$wgHooks['UserToggles'][] = array($this, 'toggle');
}
function render($form, $out) {
$out->addHTML('<fieldset><legend>My Tab</legend>');
$out->addHTML($form->getToggle('mytoggle'));
$out->addHTML('</fieldset>');
return true;
}
function toggle($extraToggles) {
global $wgMessageCache;
$extraToggles[] = 'mytoggle';
$wgMessageCache->addMessage('tog-mytoggle', 'Test checkbox');
return true;
}
}
Thank you,
DanB
Show replies by date
I figured out a (non-optimal) solution: just eliminate the
'RenderPreferencesForm' hook setup. The 'UserToggles' hook is enough.
This puts the preference on the Misc tab instead of a custom "My Tab"
tab.
The problems occurred because the checkbox was appearing on both the
Misc and My Tab tabs, so the form submit had 2 values for the
preference.
DanB