Manual:Hooks/PreferencesFormPreSave

From Linux Web Expert

PreferencesFormPreSave
<translate> Available from <tvar name=1><translate> version <tvar (Gerrit change 100113)</tvar></translate>
Allows last minute changes to a user's preferences (via User#setOption) before they're saved and gives a possibility to check which options were modified.
<translate> Define function:</translate>
public static function onPreferencesFormPreSave( array $formData, PreferencesForm $form, User $user, bool &$result, array $oldUserOptions ) { ... }
<translate> Attach hook:</translate> <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
	"Hooks": {
		"PreferencesFormPreSave": "MediaWiki\\Extension\\MyExtension\\Hooks::onPreferencesFormPreSave"
	}
}
<translate> Called from:</translate> <translate> File(s):</translate> preferences/DefaultPreferencesFactory.php
<translate> Interface:</translate> PreferencesFormPreSaveHook.php

<translate> For more information about attaching hooks, see <tvar name=1>Manual:Hooks </tvar>.</translate>
<translate> For examples of extensions using this hook, see <tvar name=cat>Category:PreferencesFormPreSave extensions</tvar>.</translate>


Details

  • $formData - An associative array containing the data from the preferences form.
  • $form - The PreferencesForm object that represents the preferences form.
  • $user - The User object that can be used to change the user's preferences.
  • &$result - The boolean return value of the Preferences::tryFormSubmit method.
  • $oldUserOptions - An associative array containing the old user options (before save).