wiki.techinc.nl/includes/htmlform/fields/HTMLExpiryField.php
Alangi Derick f6fcb74728 htmlform: Fix multiple PHPDoc annotations in htmlform module
- Add @param annotation for $params variable for __construct() method
  in the HTMLExpiryField class.
- Add @throws annotation for getOptionsOOUI() method that throws a
  MWException and remove "@return array" as this method only throw an
  exception now.

Change-Id: I292f6ae04b840f6f6f74b7c92f834f056659fbe2
2018-12-03 12:48:53 +00:00

89 lines
1.8 KiB
PHP

<?php
use MediaWiki\Widget\ExpiryInputWidget;
/**
* Expiry Field that allows the user to specify a precise date or a
* relative date string.
*/
class HTMLExpiryField extends HTMLFormField {
/**
* @var HTMLFormField
*/
protected $relativeField;
/**
* Relative Date Time Field.
* @param array $params
*/
public function __construct( array $params = [] ) {
parent::__construct( $params );
$type = !empty( $params['options'] ) ? 'selectorother' : 'text';
$this->relativeField = $this->getFieldByType( $type );
}
/**
* {@inheritdoc}
*
* Use whatever the relative field is as the standard HTML input.
*/
public function getInputHTML( $value ) {
return $this->relativeField->getInputHTML( $value );
}
protected function shouldInfuseOOUI() {
return true;
}
/**
* {@inheritdoc}
*/
protected function getOOUIModules() {
return array_merge(
[
'mediawiki.widgets.expiry',
],
$this->relativeField->getOOUIModules()
);
}
/**
* {@inheritdoc}
*/
public function getInputOOUI( $value ) {
return new ExpiryInputWidget(
$this->relativeField->getInputOOUI( $value ),
[
'id' => $this->mID,
'required' => $this->mParams['required'] ?? false,
]
);
}
/**
* {@inheritdoc}
*/
public function loadDataFromRequest( $request ) {
return $this->relativeField->loadDataFromRequest( $request );
}
/**
* Get the HTMLForm field by the type string.
*
* @param string $type
* @return \HTMLFormField
*/
protected function getFieldByType( $type ) {
$class = HTMLForm::$typeMappings[$type];
$params = $this->mParams;
$params['type'] = $type;
$params['class'] = $class;
// Remove Parameters that are being used on the parent.
unset( $params['label-message'] );
return new $class( $params );
}
}