Manual:Hooks/PreferencesFormPreSave

From MediaWiki.org
Jump to navigation Jump to search
PreferencesFormPreSave
Available from version 1.23.0 (Gerrit change 100113)
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.
Define function:
public static function onPreferencesFormPreSave( array $formData, PreferencesForm $form, User $user, boolean &$result, array $oldUserOptions ) { ... }
Attach hook:

In extension.json:

{
	"Hooks": {
		"PreferencesFormPreSave": "MyExtensionHooks::onPreferencesFormPreSave"
	}
}

For MediaWiki ≤1.25:

$wgHooks['PreferencesFormPreSave'][] = 'MyExtensionHooks::onPreferencesFormPreSave';
Called from: File(s): Preferences.php

For more information about attaching hooks, see Manual:Hooks.
For examples of extensions using this hook, see Category:PreferencesFormPreSave extensions.

Details[edit]

  • $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).