3 namespace MediaWiki\HTMLForm\Field
;
5 use MediaWiki\Html\Html
;
6 use MediaWiki\HTMLForm\HTMLFormField
;
9 * Enables HTMLFormField elements to be build with a button.
11 * TODO This class should be a trait
15 class HTMLFormFieldWithButton
extends HTMLFormField
{
16 /** @var string CSS class for the button in this field */
17 protected $mButtonClass = '';
19 /** @var string|int Element ID for the button in this field */
20 protected $mButtonId = '';
22 /** @var string Name the button in this field */
23 protected $mButtonName = '';
25 /** @var string Type of the button in this field (e.g. button or submit) */
26 protected $mButtonType = 'submit';
28 /** @var string Value for the button in this field */
29 protected $mButtonValue;
31 /** @var string[] Value for the button in this field */
32 protected $mButtonFlags = [ 'progressive' ];
38 public function __construct( $info ) {
39 if ( isset( $info['buttonclass'] ) ) {
40 $this->mButtonClass
= $info['buttonclass'];
42 if ( isset( $info['buttonid'] ) ) {
43 $this->mButtonId
= $info['buttonid'];
45 if ( isset( $info['buttonname'] ) ) {
46 $this->mButtonName
= $info['buttonname'];
48 if ( isset( $info['buttondefault'] ) ) {
49 $this->mButtonValue
= $info['buttondefault'];
51 if ( isset( $info['buttontype'] ) ) {
52 $this->mButtonType
= $info['buttontype'];
54 if ( isset( $info['buttonflags'] ) ) {
55 $this->mButtonFlags
= $info['buttonflags'];
57 parent
::__construct( $info );
60 public function getInputHTML( $value ) {
62 'class' => 'mw-htmlform-submit ' . $this->mButtonClass
,
63 'id' => $this->mButtonId
,
64 ] +
$this->getAttributes( [ 'disabled', 'tabindex' ] );
66 return Html
::input( $this->mButtonName
, $this->mButtonValue
, $this->mButtonType
, $attr );
69 public function getInputOOUI( $value ) {
70 return new \OOUI\
ButtonInputWidget( [
71 'name' => $this->mButtonName
,
72 'value' => $this->mButtonValue
,
73 'type' => $this->mButtonType
,
74 'label' => $this->mButtonValue
,
75 'flags' => $this->mButtonFlags
,
76 'id' => $this->mButtonId ?
: null,
77 ] + \OOUI\Element
::configFromHtmlAttributes(
78 $this->getAttributes( [ 'disabled', 'tabindex' ] )
83 * Combines the passed element with a button.
84 * @param string $element Element to combine the button with.
87 public function getElement( $element ) {
88 return $element . "\u{00A0}" . $this->getInputHTML( '' );
92 /** @deprecated class alias since 1.42 */
93 class_alias( HTMLFormFieldWithButton
::class, 'HTMLFormFieldWithButton' );