Merge "Bump wikimedia/parsoid to 0.21.0-a11"
[mediawiki.git] / includes / htmlform / fields / HTMLHiddenField.php
blob5b19093d22a048f89909fe50eb0a8adc643773d4
1 <?php
3 namespace MediaWiki\HTMLForm\Field;
5 use MediaWiki\HTMLForm\HTMLFormField;
7 /*
8 * @stable to extend
9 */
10 class HTMLHiddenField extends HTMLFormField {
11 /** @var bool */
12 protected $outputAsDefault = true;
14 /**
15 * @stable to call
16 * @inheritDoc
18 public function __construct( $params ) {
19 parent::__construct( $params );
21 if ( isset( $this->mParams['output-as-default'] ) ) {
22 $this->outputAsDefault = (bool)$this->mParams['output-as-default'];
25 # Per HTML5 spec, hidden fields cannot be 'required'
26 # https://www.w3.org/TR/html5/forms.html#hidden-state-%28type=hidden%29
27 unset( $this->mParams['required'] );
30 public function getHiddenFieldData( $value ) {
31 $params = [];
32 if ( $this->mID ) {
33 $params['id'] = $this->mID;
36 if ( $this->outputAsDefault ) {
37 $value = $this->mDefault;
40 return [ $this->mName, $value, $params ];
43 public function getTableRow( $value ) {
44 [ $name, $value, $params ] = $this->getHiddenFieldData( $value );
45 $this->mParent->addHiddenField( $name, $value, $params );
46 return '';
49 /**
50 * @param string $value
51 * @return string
52 * @since 1.20
54 public function getDiv( $value ) {
55 return $this->getTableRow( $value );
58 /**
59 * @param string $value
60 * @return string
61 * @since 1.20
63 public function getRaw( $value ) {
64 return $this->getTableRow( $value );
67 public function getCodex( $value ) {
68 return $this->getTableRow( $value );
71 public function getInputHTML( $value ) {
72 return '';
75 public function canDisplayErrors() {
76 return false;
79 public function hasVisibleOutput() {
80 return false;
84 /** @deprecated class alias since 1.42 */
85 class_alias( HTMLHiddenField::class, 'HTMLHiddenField' );