MediaWiki  master
HTMLHiddenField.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * @stable to extend
5  */
7  protected $outputAsDefault = true;
8 
13  public function __construct( $params ) {
14  parent::__construct( $params );
15 
16  if ( isset( $this->mParams['output-as-default'] ) ) {
17  $this->outputAsDefault = (bool)$this->mParams['output-as-default'];
18  }
19 
20  # Per HTML5 spec, hidden fields cannot be 'required'
21  # https://www.w3.org/TR/html5/forms.html#hidden-state-%28type=hidden%29
22  unset( $this->mParams['required'] );
23  }
24 
25  public function getHiddenFieldData( $value ) {
26  $params = [];
27  if ( $this->mID ) {
28  $params['id'] = $this->mID;
29  }
30 
31  if ( $this->outputAsDefault ) {
32  $value = $this->mDefault;
33  }
34 
35  return [ $this->mName, $value, $params ];
36  }
37 
38  public function getTableRow( $value ) {
39  [ $name, $value, $params ] = $this->getHiddenFieldData( $value );
40  $this->mParent->addHiddenField( $name, $value, $params );
41  return '';
42  }
43 
49  public function getDiv( $value ) {
50  return $this->getTableRow( $value );
51  }
52 
58  public function getRaw( $value ) {
59  return $this->getTableRow( $value );
60  }
61 
62  public function getInputHTML( $value ) {
63  return '';
64  }
65 
66  public function canDisplayErrors() {
67  return false;
68  }
69 
70  public function hasVisibleOutput() {
71  return false;
72  }
73 }
The parent class to generate form fields.
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself.
getTableRow( $value)
Get the complete table row for the input, including help text, labels, and whatever.
__construct( $params)
canDisplayErrors()
True if this field type is able to display errors; false if validation errors need to be displayed in...
hasVisibleOutput()
If this field has a user-visible output or not.
getHiddenFieldData( $value)