MediaWiki master
HTMLExpiryField.php
Go to the documentation of this file.
1<?php
2
4
8
16
20 protected $relativeField;
21
28 public function __construct( array $params = [] ) {
29 parent::__construct( $params );
30
31 $type = !empty( $params['options'] ) ? 'selectorother' : 'text';
32 $this->relativeField = $this->getFieldByType( $type );
33 }
34
40 public function getInputHTML( $value ) {
41 return $this->relativeField->getInputHTML( $value );
42 }
43
44 protected function shouldInfuseOOUI() {
45 return true;
46 }
47
51 protected function getOOUIModules() {
52 return array_merge(
53 [
54 'mediawiki.widgets.expiry',
55 ],
56 $this->relativeField->getOOUIModules()
57 );
58 }
59
63 public function getInputOOUI( $value ) {
64 return new ExpiryInputWidget(
65 $this->relativeField->getInputOOUI( $value ),
66 [
67 'id' => $this->mID,
68 'required' => $this->mParams['required'] ?? false,
69 ]
70 );
71 }
72
76 public function loadDataFromRequest( $request ) {
77 return $this->relativeField->loadDataFromRequest( $request );
78 }
79
86 protected function getFieldByType( $type ) {
87 $class = HTMLForm::$typeMappings[$type];
88 $params = $this->mParams;
89 $params['type'] = $type;
90 $params['class'] = $class;
91
92 // Remove Parameters that are being used on the parent.
93 unset( $params['label-message'] );
94 return new $class( $params );
95 }
96
97}
98
100class_alias( HTMLExpiryField::class, 'HTMLExpiryField' );
Expiry Field that allows the user to specify a precise date or a relative date string.
getOOUIModules()
Get the list of extra ResourceLoader modules which must be loaded client-side before it's possible to...
__construct(array $params=[])
Relative Date Time Field.
getFieldByType( $type)
Get the HTMLForm field by the type string.
loadDataFromRequest( $request)
Get the value that this input has been set to from a posted form, or the input's default value if it ...
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself....
shouldInfuseOOUI()
Whether the field should be automatically infused.
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.Defaults to false, which getOOUI will interpret as "...
The parent class to generate form fields.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:206
static string[] $typeMappings
A mapping of 'type' inputs onto standard HTMLFormField subclasses.
Definition HTMLForm.php:210