Manual:Hooks/AuthChangeFormFields/ja

This page is a translated version of the page Manual:Hooks/AuthChangeFormFields and the translation is 9% complete.
AuthChangeFormFields
バージョン 1.27.0 から利用可能
Allows modification of AuthManager-based forms
関数の定義:
public static function onAuthChangeFormFields( $requests, $fieldInfo, &$formDescriptor, $action ) { ... }
フックのアタッチ: extension.json 内:
{
	"Hooks": {
		"AuthChangeFormFields": "MediaWiki\\Extension\\MyExtension\\Hooks::onAuthChangeFormFields"
	}
}
呼び出し元: ファイル: specialpage/AuthManagerSpecialPage.php
インターフェイス: AuthChangeFormFieldsHook.php

フックの設定についての詳細情報は Manual:フック を参照してください。
このフックを使用する拡張機能の例については、Category:AuthChangeFormFields extensions/ja を参照してください。


詳細

  • $requests - array of AuthenticationRequests the fields are created from
  • $fieldInfo - field information array (union of all AuthenticationRequest::getFieldInfo() responses).
  • &$formDescriptor - HTMLForm descriptor. The special key weight can be set to change the order of the fields.
  • $action - one of the AuthManager::ACTION_* constants.

$formDescriptor will contain the definition of the HTMLForm (the descriptor array that will be passed to the HTMLForm constructor); the hook allows modifying it. The form field names (array keys) will match the field names in the requests. $fieldInfo is the result of AuthenticationRequest::mergeFieldInfo( $requests ).

Caveats:

  • Changing the requests is not allowed.
  • Adding fields which take data is not allowed (adding info fields is fine). Use an authentication provider's getAuthenticationRequests() method to add new fields.
  • Any validation, permission check or other business logic in the hook can be trivially circumvented by using the API. Business logic should be in the providers.
  • Any vital information must be made available via the API as well. If it's for users (e.g. the text of a CAPTCHA) use a null field in AuthenticationRequest::getFieldInfo() (which can be hidden/changed for the web UI from this hook if needed). If it's for machines (e.g. the public API key for the CAPTCHA) use AuthenticationRequest::getMetadata().

The hook is primarily meant to enhance fields defined by a provider in the same extension (e.g. change a textfield into a typeahead or other interactive widget), change the position of the widget and provide help links or other extra information. Changing form fields belonging to core or other extensions is allowed but should preferably be avoided as it makes the code more fragile.

関連項目