MediaWiki  master
HTMLFormFieldWithButton.php
Go to the documentation of this file.
1 <?php
2 
4 
14  protected $mButtonClass = '';
15 
17  protected $mButtonId = '';
18 
20  protected $mButtonName = '';
21 
23  protected $mButtonType = 'submit';
24 
26  protected $mButtonValue;
27 
29  protected $mButtonFlags = [ 'progressive' ];
30 
35  public function __construct( $info ) {
36  if ( isset( $info['buttonclass'] ) ) {
37  $this->mButtonClass = $info['buttonclass'];
38  }
39  if ( isset( $info['buttonid'] ) ) {
40  $this->mButtonId = $info['buttonid'];
41  }
42  if ( isset( $info['buttonname'] ) ) {
43  $this->mButtonName = $info['buttonname'];
44  }
45  if ( isset( $info['buttondefault'] ) ) {
46  $this->mButtonValue = $info['buttondefault'];
47  }
48  if ( isset( $info['buttontype'] ) ) {
49  $this->mButtonType = $info['buttontype'];
50  }
51  if ( isset( $info['buttonflags'] ) ) {
52  $this->mButtonFlags = $info['buttonflags'];
53  }
54  parent::__construct( $info );
55  }
56 
57  public function getInputHTML( $value ) {
58  $attr = [
59  'class' => 'mw-htmlform-submit ' . $this->mButtonClass,
60  'id' => $this->mButtonId,
61  ] + $this->getAttributes( [ 'disabled', 'tabindex' ] );
62 
63  return Html::input( $this->mButtonName, $this->mButtonValue, $this->mButtonType, $attr );
64  }
65 
66  public function getInputOOUI( $value ) {
67  return new OOUI\ButtonInputWidget( [
68  'name' => $this->mButtonName,
69  'value' => $this->mButtonValue,
70  'type' => $this->mButtonType,
71  'label' => $this->mButtonValue,
72  'flags' => $this->mButtonFlags,
73  'id' => $this->mButtonId ?: null,
74  ] + OOUI\Element::configFromHtmlAttributes(
75  $this->getAttributes( [ 'disabled', 'tabindex' ] )
76  ) );
77  }
78 
84  public function getElement( $element ) {
85  return $element . "\u{00A0}" . $this->getInputHTML( '' );
86  }
87 }
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.
This class is a collection of static functions that serve two purposes:
Definition: Html.php:57