| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\HTMLForm\Field; |
| 4 |
|
| 5 |
use MediaWiki\Html\Html; |
| 6 |
use MediaWiki\HTMLForm\HTMLFormField; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
class HTMLFormFieldWithButton extends HTMLFormField { |
| 16 |
|
| 17 |
protected $mButtonClass = ''; |
| 18 |
|
| 19 |
|
| 20 |
protected $mButtonId = ''; |
| 21 |
|
| 22 |
|
| 23 |
protected $mButtonName = ''; |
| 24 |
|
| 25 |
|
| 26 |
protected $mButtonType = 'submit'; |
| 27 |
|
| 28 |
|
| 29 |
protected $mButtonValue; |
| 30 |
|
| 31 |
|
| 32 |
protected $mButtonFlags = [ 'progressive' ]; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public function __construct( $info ) { |
| 39 |
if ( isset( $info['buttonclass'] ) ) { |
| 40 |
$this->mButtonClass = $info['buttonclass']; |
| 41 |
} |
| 42 |
if ( isset( $info['buttonid'] ) ) { |
| 43 |
$this->mButtonId = $info['buttonid']; |
| 44 |
} |
| 45 |
if ( isset( $info['buttonname'] ) ) { |
| 46 |
$this->mButtonName = $info['buttonname']; |
| 47 |
} |
| 48 |
if ( isset( $info['buttondefault'] ) ) { |
| 49 |
$this->mButtonValue = $info['buttondefault']; |
| 50 |
} |
| 51 |
if ( isset( $info['buttontype'] ) ) { |
| 52 |
$this->mButtonType = $info['buttontype']; |
| 53 |
} |
| 54 |
if ( isset( $info['buttonflags'] ) ) { |
| 55 |
$this->mButtonFlags = $info['buttonflags']; |
| 56 |
} |
| 57 |
parent::__construct( $info ); |
| 58 |
} |
| 59 |
|
| 60 |
public function getInputHTML( $value ) { |
| 61 |
$attr = [ |
| 62 |
'class' => 'mw-htmlform-submit ' . $this->mButtonClass, |
| 63 |
'id' => $this->mButtonId, |
| 64 |
] + $this->getAttributes( [ 'disabled', 'tabindex' ] ); |
| 65 |
|
| 66 |
return Html::input( $this->mButtonName, $this->mButtonValue, $this->mButtonType, $attr ); |
| 67 |
} |
| 68 |
|
| 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' ] ) |
| 79 |
) ); |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public function getElement( $element ) { |
| 88 |
return $element . "\u{00A0}" . $this->getInputHTML( '' ); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
class_alias( HTMLFormFieldWithButton::class, 'HTMLFormFieldWithButton' ); |