MediaWiki  master
HTMLFormFieldWithButton.php
Go to the documentation of this file.
1 <?php
11  protected $mButtonClass = '';
12 
14  protected $mButtonId = '';
15 
17  protected $mButtonName = '';
18 
20  protected $mButtonType = 'submit';
21 
23  protected $mButtonValue;
24 
26  protected $mButtonFlags = [ 'progressive' ];
27 
32  public function __construct( $info ) {
33  if ( isset( $info['buttonclass'] ) ) {
34  $this->mButtonClass = $info['buttonclass'];
35  }
36  if ( isset( $info['buttonid'] ) ) {
37  $this->mButtonId = $info['buttonid'];
38  }
39  if ( isset( $info['buttonname'] ) ) {
40  $this->mButtonName = $info['buttonname'];
41  }
42  if ( isset( $info['buttondefault'] ) ) {
43  $this->mButtonValue = $info['buttondefault'];
44  }
45  if ( isset( $info['buttontype'] ) ) {
46  $this->mButtonType = $info['buttontype'];
47  }
48  if ( isset( $info['buttonflags'] ) ) {
49  $this->mButtonFlags = $info['buttonflags'];
50  }
51  parent::__construct( $info );
52  }
53 
54  public function getInputHTML( $value ) {
55  $attr = [
56  'class' => 'mw-htmlform-submit ' . $this->mButtonClass,
57  'id' => $this->mButtonId,
58  ] + $this->getAttributes( [ 'disabled', 'tabindex' ] );
59 
60  return Html::input( $this->mButtonName, $this->mButtonValue, $this->mButtonType, $attr );
61  }
62 
63  public function getInputOOUI( $value ) {
64  return new OOUI\ButtonInputWidget( [
65  'name' => $this->mButtonName,
66  'value' => $this->mButtonValue,
67  'type' => $this->mButtonType,
68  'label' => $this->mButtonValue,
69  'flags' => $this->mButtonFlags,
70  'id' => $this->mButtonId ?: null,
71  ] + OOUI\Element::configFromHtmlAttributes(
72  $this->getAttributes( [ 'disabled', 'tabindex' ] )
73  ) );
74  }
75 
81  public function getElement( $element ) {
82  return $element . "\u{00A0}" . $this->getInputHTML( '' );
83  }
84 }
Enables HTMLFormField elements to be build with a button.
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself.
string int $mButtonId
Element ID for the button in this field.
getElement( $element)
Combines the passed element with a button.
string $mButtonClass
CSS class for the button in this field.
string $mButtonValue
Value for the button in this field.
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.
string $mButtonName
Name the button in this field.
string[] $mButtonFlags
Value for the button in this field.
string $mButtonType
Type of the button in this field (e.g.
The parent class to generate form fields.
getAttributes(array $list)
Returns the given attributes from the parameters.
static input( $name, $value='', $type='text', array $attribs=[])
Convenience function to produce an "<input>" element.
Definition: Html.php:688