wiki.techinc.nl/includes/htmlform/fields/HTMLHiddenField.php
James D. Forrester 59c0aa2134 Namespace HTMLForm and friends
Bug: T353458
Change-Id: I09e66c3223018ec47e0549ee7f6a590b676f4eef
2024-02-14 08:18:33 -05:00

80 lines
1.6 KiB
PHP

<?php
namespace MediaWiki\HTMLForm\Field;
use MediaWiki\HTMLForm\HTMLFormField;
/*
* @stable to extend
*/
class HTMLHiddenField extends HTMLFormField {
protected $outputAsDefault = true;
/**
* @stable to call
* @inheritDoc
*/
public function __construct( $params ) {
parent::__construct( $params );
if ( isset( $this->mParams['output-as-default'] ) ) {
$this->outputAsDefault = (bool)$this->mParams['output-as-default'];
}
# Per HTML5 spec, hidden fields cannot be 'required'
# https://www.w3.org/TR/html5/forms.html#hidden-state-%28type=hidden%29
unset( $this->mParams['required'] );
}
public function getHiddenFieldData( $value ) {
$params = [];
if ( $this->mID ) {
$params['id'] = $this->mID;
}
if ( $this->outputAsDefault ) {
$value = $this->mDefault;
}
return [ $this->mName, $value, $params ];
}
public function getTableRow( $value ) {
[ $name, $value, $params ] = $this->getHiddenFieldData( $value );
$this->mParent->addHiddenField( $name, $value, $params );
return '';
}
/**
* @param string $value
* @return string
* @since 1.20
*/
public function getDiv( $value ) {
return $this->getTableRow( $value );
}
/**
* @param string $value
* @return string
* @since 1.20
*/
public function getRaw( $value ) {
return $this->getTableRow( $value );
}
public function getInputHTML( $value ) {
return '';
}
public function canDisplayErrors() {
return false;
}
public function hasVisibleOutput() {
return false;
}
}
/** @deprecated since 1.42 */
class_alias( HTMLHiddenField::class, 'HTMLHiddenField' );