MediaWiki REL1_35
HTMLFormFieldCloner Class Reference

A container for HTMLFormFields that allows for multiple copies of the set of fields to be displayed to and entered by the user. More...

Inheritance diagram for HTMLFormFieldCloner:
Collaboration diagram for HTMLFormFieldCloner:

Public Member Functions

 __construct ( $params)
 Initialise the object.
 
 cancelSubmit ( $values, $alldata)
 Override this function if the control can somehow trigger a form submission that shouldn't actually submit the HTMLForm.Stable to override

Since
1.23
Parameters
string | array$valueThe value the field was submitted with
array$alldataThe data collected from the form
Returns
bool True to cancel the submission
-param array[] $values
 
 getDefault ()
 Stable to override.
 
 getInputHTML ( $values)
 This function must be implemented to return the HTML to generate the input object itself.
 
 getInputOOUI ( $values)
 Same as getInputHTML, but returns an OOUI object.
 
 loadDataFromRequest ( $request)
 Get the value that this input has been set to from a posted form, or the input's default value if it has not been set.
 
 validate ( $values, $alldata)
 Override this function to add specific validation checks on the field input.Don't forget to call parent::validate() to ensure that the user-defined callback mValidationCallback is still run Stable to override
Parameters
string | array$valueThe value the field was submitted with
array$alldataThe data collected from the form
Returns
bool|string|Message True on success, or String/Message error to display, or false to fail validation without displaying an error.
-param array[] $values
 
- Public Member Functions inherited from HTMLFormField
 canDisplayErrors ()
 True if this field type is able to display errors; false if validation errors need to be displayed in the main HTMLForm error area.
 
 filter ( $value, $alldata)
 Stable to override.
 
 getAttributes (array $list)
 Returns the given attributes from the parameters Stable to override.
 
 getDiv ( $value)
 Get the complete div for the input, including help text, labels, and whatever.
 
 getErrorsAndErrorClass ( $value)
 Determine form errors to display and their classes.
 
 getErrorsRaw ( $value)
 Determine form errors to display, returning them in an array.
 
 getHelpText ()
 Determine the help text to display Stable to override.
 
 getHelpTextHtmlDiv ( $helptext)
 Generate help text HTML in div format.
 
 getHelpTextHtmlRaw ( $helptext)
 Generate help text HTML formatted for raw output.
 
 getHelpTextHtmlTable ( $helptext)
 Generate help text HTML in table format.
 
 getInline ( $value)
 Get the complete field as an inline element.
 
 getLabel ()
 Stable to override.
 
 getLabelHtml ( $cellAttributes=[])
 Stable to override.
 
 getOOUI ( $value)
 Get the OOUI version of the div.
 
 getOptions ()
 Fetch the array of options from the field's parameters.
 
 getOptionsOOUI ()
 Get options and make them into arrays suitable for OOUI.
 
 getRaw ( $value)
 Get the complete raw fields for the input, including help text, labels, and whatever.
 
 getTableRow ( $value)
 Get the complete table row for the input, including help text, labels, and whatever.
 
 getTooltipAndAccessKey ()
 Returns the attributes required for the tooltip and accesskey, for Html::element() etc.
 
 getTooltipAndAccessKeyOOUI ()
 Returns the attributes required for the tooltip and accesskey, for OOUI widgets' config.
 
 getVForm ( $value)
 Get the complete field for the input, including help text, labels, and whatever.
 
 hasVisibleOutput ()
 If this field has a user-visible output or not.
 
 isHelpInline ()
 Determine if the help text should be displayed inline.
 
 isHidden ( $alldata)
 Test whether this field is supposed to be hidden, based on the values of the other form fields.
 
 msg ( $key,... $params)
 Get a translated interface message.
 
 needsJSForHtml5FormValidation ()
 Whether this field requires the user agent to have JavaScript enabled for the client-side HTML5 form validation to work correctly.
 
 setShowEmptyLabel ( $show)
 Tell the field whether to generate a separate label element if its label is blank.
 
 skipLoadData ( $request)
 Skip this field when collecting data.
 

Protected Member Functions

 createFieldsForKey ( $key)
 Create the HTMLFormFields that go inside this element, using the specified key.
 
 getCreateButtonHtml ()
 
 getDeleteButtonHtml ( $key)
 
 getInputHTMLForKey ( $key, array $values)
 Get the input HTML for the specified key.
 
 getInputOOUIForKey ( $key, array $values)
 Get the input OOUI HTML for the specified key.
 
 needsLabel ()
 Should this field have a label, or is there no input element with the appropriate id for the label to point to? Stable to override.
 
 rekeyValuesArray ( $key, $values)
 Re-key the specified values array to match the names applied by createFieldsForKey().
 
- Protected Member Functions inherited from HTMLFormField
 getClassName ()
 Gets the non namespaced class name.
 
 getFieldLayoutOOUI ( $inputField, $config)
 Get a FieldLayout (or subclass thereof) to wrap this field in when using OOUI output.
 
 getLabelAlignOOUI ()
 Get label alignment when generating field for OOUI.
 
 getMessage ( $value)
 Turns a *-message parameter (which could be a MessageSpecifier, or a message name, or a name + parameters array) into a Message.
 
 getNearestFieldByName ( $alldata, $name)
 Fetch a field value from $alldata for the closest field matching a given name.
 
 getOOUIModules ()
 Get the list of extra ResourceLoader modules which must be loaded client-side before it's possible to infuse this field's OOUI widget.
 
 isHiddenRecurse (array $alldata, array $params)
 Helper function for isHidden to handle recursive data structures.
 
 isSubmitAttempt (WebRequest $request)
 Can we assume that the request is an attempt to submit a HTMLForm, as opposed to an attempt to just view it? This can't normally be distinguished for e.g.
 
 shouldInfuseOOUI ()
 Whether the field should be automatically infused.
 

Protected Attributes

string $uniqueId
 String uniquely identifying this cloner instance and unlikely to exist otherwise in the generated HTML, while still being valid as part of an HTML id.
 
- Protected Attributes inherited from HTMLFormField
 $mClass = ''
 
 $mDefault
 
 $mDir
 
 $mFilterCallback
 
 $mHelpClass = false
 
 $mHideIf = null
 
 $mID
 
 $mLabel
 
 $mName
 
array bool null $mOptions = false
 
 $mOptionsLabelsNotFromMessage = false
 
bool $mShowEmptyLabels = true
 If true will generate an empty div element with no label.
 
 $mValidationCallback
 
 $mVFormClass = ''
 

Static Private Attributes

static $counter = 0
 

Additional Inherited Members

- Static Public Member Functions inherited from HTMLFormField
static flattenOptions ( $options)
 flatten an array of options to a single array, for instance, a set of "<options>" inside "<optgroups>".
 
static forceToStringRecursive ( $array)
 Recursively forces values in an array to strings, because issues arise with integer 0 as a value.
 
- Public Attributes inherited from HTMLFormField
array array[] $mParams
 
HTMLForm null $mParent
 
- Static Protected Member Functions inherited from HTMLFormField
static formatErrors ( $errors)
 Formats one or more errors as accepted by field validation-callback.
 

Detailed Description

A container for HTMLFormFields that allows for multiple copies of the set of fields to be displayed to and entered by the user.

Recognized parameters, besides the general ones, include: fields - HTMLFormField descriptors for the subfields this cloner manages. The format is just like for the HTMLForm. A field with key 'delete' is special: it must have type = submit and will serve to delete the group of fields. required - If specified, at least one group of fields must be submitted. format - HTMLForm display format to use when displaying the subfields: 'table', 'div', or 'raw'. This is ignored when using OOUI. row-legend - If non-empty, each group of subfields will be enclosed in a fieldset. The value is the name of a message key to use as the legend. create-button-message - Message to use as the text of the button to add an additional group of fields. delete-button-message - Message to use as the text of automatically- generated 'delete' button. Ignored if 'delete' is included in 'fields'.

In the generated HTML, the subfields will be named along the lines of "clonerName[index][fieldname]", with ids "clonerId--index--fieldid". 'index' may be a number or an arbitrary string, and may likely change when the page is resubmitted. Cloners may be nested, resulting in field names along the lines of "cloner1Name[index1][cloner2Name][index2][fieldname]" and corresponding ids.

Use of cloner may result in submissions of the page that are not submissions of the HTMLForm, when non-JavaScript clients use the create or remove buttons.

The result is an array, with values being arrays mapping subfield names to their values. On non-HTMLForm-submission page loads, there may also be additional (string) keys present with other types of values.

Since
1.23 Stable to extend

Definition at line 39 of file HTMLFormFieldCloner.php.

Constructor & Destructor Documentation

◆ __construct()

HTMLFormFieldCloner::__construct (   $params)

Initialise the object.

Stable to call

Parameters
array$paramsAssociative Array. See HTMLForm doc for syntax.
Since
1.22 The 'label' attribute no longer accepts raw HTML, use 'label-raw' instead
Exceptions
MWException

Reimplemented from HTMLFormField.

Definition at line 52 of file HTMLFormFieldCloner.php.

References HTMLFormField\getClassName().

Member Function Documentation

◆ cancelSubmit()

HTMLFormFieldCloner::cancelSubmit (   $values,
  $alldata 
)

Override this function if the control can somehow trigger a form submission that shouldn't actually submit the HTMLForm.Stable to override

Since
1.23
Parameters
string | array$valueThe value the field was submitted with
array$alldataThe data collected from the form
Returns
bool True to cancel the submission
-param array[] $values

Reimplemented from HTMLFormField.

Definition at line 223 of file HTMLFormFieldCloner.php.

References createFieldsForKey().

◆ createFieldsForKey()

HTMLFormFieldCloner::createFieldsForKey (   $key)
protected

Create the HTMLFormFields that go inside this element, using the specified key.

Parameters
string$keyArray key under which these fields should be named
Returns
HTMLFormField[]

Definition at line 91 of file HTMLFormFieldCloner.php.

References HTMLFormField\$mHideIf.

Referenced by cancelSubmit(), getDefault(), getInputHTMLForKey(), loadDataFromRequest(), and validate().

◆ getCreateButtonHtml()

HTMLFormFieldCloner::getCreateButtonHtml ( )
protected

Definition at line 378 of file HTMLFormFieldCloner.php.

◆ getDefault()

HTMLFormFieldCloner::getDefault ( )

Stable to override.

Returns
mixed

Reimplemented from HTMLFormField.

Definition at line 198 of file HTMLFormFieldCloner.php.

References createFieldsForKey().

Referenced by loadDataFromRequest().

◆ getDeleteButtonHtml()

HTMLFormFieldCloner::getDeleteButtonHtml (   $key)
protected
Parameters
string$keyArray key indicating to which field the delete button belongs
Returns
HTMLFormField

Definition at line 364 of file HTMLFormFieldCloner.php.

Referenced by getInputHTMLForKey().

◆ getInputHTML()

HTMLFormFieldCloner::getInputHTML (   $value)

This function must be implemented to return the HTML to generate the input object itself.

It should not implement the surrounding table cells/rows, or labels/help messages.

Parameters
mixed$valueThe value to set the input to; eg a default text for a text input.
Returns
string Valid HTML.

Reimplemented from HTMLFormField.

Definition at line 391 of file HTMLFormFieldCloner.php.

◆ getInputHTMLForKey()

HTMLFormFieldCloner::getInputHTMLForKey (   $key,
array  $values 
)
protected

Get the input HTML for the specified key.

Parameters
string$keyArray key under which the fields should be named
array$values
Returns
string

Definition at line 288 of file HTMLFormFieldCloner.php.

References createFieldsForKey(), getDeleteButtonHtml(), and HTMLFormField\msg().

◆ getInputOOUI()

HTMLFormFieldCloner::getInputOOUI (   $value)

Same as getInputHTML, but returns an OOUI object.

Defaults to false, which getOOUI will interpret as "use the HTML version" Stable to override

Parameters
string$value
Returns
OOUI\Widget|false

Reimplemented from HTMLFormField.

Definition at line 471 of file HTMLFormFieldCloner.php.

◆ getInputOOUIForKey()

HTMLFormFieldCloner::getInputOOUIForKey (   $key,
array  $values 
)
protected

Get the input OOUI HTML for the specified key.

Parameters
string$keyArray key under which the fields should be named
array$values
Returns
string

Definition at line 424 of file HTMLFormFieldCloner.php.

◆ loadDataFromRequest()

HTMLFormFieldCloner::loadDataFromRequest (   $request)

Get the value that this input has been set to from a posted form, or the input's default value if it has not been set.

Stable to override

Parameters
WebRequest$request
Returns
mixed The value

Reimplemented from HTMLFormField.

Definition at line 143 of file HTMLFormFieldCloner.php.

References createFieldsForKey(), getDefault(), and rekeyValuesArray().

◆ needsLabel()

HTMLFormFieldCloner::needsLabel ( )
protected

Should this field have a label, or is there no input element with the appropriate id for the label to point to? Stable to override.

Returns
bool True to output a label, false to suppress

Reimplemented from HTMLFormField.

Definition at line 139 of file HTMLFormFieldCloner.php.

◆ rekeyValuesArray()

HTMLFormFieldCloner::rekeyValuesArray (   $key,
  $values 
)
protected

Re-key the specified values array to match the names applied by createFieldsForKey().

Parameters
string$keyArray key under which these fields should be named
array$valuesValues array from the request
Returns
array

Definition at line 130 of file HTMLFormFieldCloner.php.

Referenced by loadDataFromRequest().

◆ validate()

HTMLFormFieldCloner::validate (   $values,
  $alldata 
)

Override this function to add specific validation checks on the field input.Don't forget to call parent::validate() to ensure that the user-defined callback mValidationCallback is still run Stable to override

Parameters
string | array$valueThe value the field was submitted with
array$alldataThe data collected from the form
Returns
bool|string|Message True on success, or String/Message error to display, or false to fail validation without displaying an error.
-param array[] $values

Reimplemented from HTMLFormField.

Definition at line 247 of file HTMLFormFieldCloner.php.

References createFieldsForKey(), and HTMLFormField\msg().

Member Data Documentation

◆ $counter

HTMLFormFieldCloner::$counter = 0
staticprivate

Definition at line 40 of file HTMLFormFieldCloner.php.

◆ $uniqueId

string HTMLFormFieldCloner::$uniqueId
protected

String uniquely identifying this cloner instance and unlikely to exist otherwise in the generated HTML, while still being valid as part of an HTML id.

Definition at line 47 of file HTMLFormFieldCloner.php.


The documentation for this class was generated from the following file: