Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1431608
CheckboxInputWidget.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
CheckboxInputWidget.php
View Options
<?php
namespace
OOUI
;
/**
* Checkbox input widget.
*/
class
CheckboxInputWidget
extends
InputWidget
{
use
RequiredElement
;
/* Static Properties */
/** @var string */
public
static
$tagName
=
'span'
;
/* Properties */
/**
* Whether the checkbox is selected.
*
* @var bool
*/
protected
$selected
;
/**
* @var bool
*/
protected
$indeterminate
;
/**
* @var IconWidget
*/
protected
$checkIcon
;
/**
* @param array $config Configuration options
* - bool $config['selected'] Whether the checkbox is initially selected
* (default: false)
* - bool $config['indeterminate'] Whether the checkbox is in the indeterminate state.
* (default: false)
*/
public
function
__construct
(
array
$config
=
[]
)
{
// Parent constructor
parent
::
__construct
(
$config
);
// Properties
$this
->
checkIcon
=
new
IconWidget
(
[
'icon'
=>
'check'
,
'classes'
=>
[
'oo-ui-checkboxInputWidget-checkIcon'
],
]
);
// Traits
$this
->
initializeRequiredElement
(
array_merge
(
[
'indicatorElement'
=>
null
],
$config
)
);
// Initialization
$this
->
addClasses
(
[
'oo-ui-checkboxInputWidget'
]
);
// Required for pretty styling in WikimediaUI theme
$this
->
appendContent
(
$this
->
checkIcon
);
$this
->
setSelected
(
$config
[
'selected'
]
??
false
);
$this
->
setIndeterminate
(
$config
[
'indeterminate'
]
??
false
);
}
/** @inheritDoc */
protected
function
getInputElement
(
$config
)
{
return
(
new
Tag
(
'input'
)
)->
setAttributes
(
[
'type'
=>
'checkbox'
]
);
}
/**
* Set selection state of this checkbox.
*
* @param bool $state Whether the checkbox is selected
* @return $this
*/
public
function
setSelected
(
$state
)
{
$this
->
selected
=
(
bool
)
$state
;
if
(
$this
->
selected
)
{
$this
->
input
->
setAttributes
(
[
'checked'
=>
'checked'
]
);
}
else
{
$this
->
input
->
removeAttributes
(
[
'checked'
]
);
}
return
$this
;
}
/**
* Check if this checkbox is selected.
*
* @return bool Checkbox is selected
*/
public
function
isSelected
()
{
return
$this
->
selected
;
}
/**
* Set indeterminate state of this checkbox.
*
* @param bool $state Whether the checkbox is indeterminate
* @return $this
*/
public
function
setIndeterminate
(
$state
)
{
$this
->
indeterminate
=
(
bool
)
$state
;
// NB: A checkbox can't be made indeterminate through HTML,
// there is no indeterminate attribute. We can only store
// the state for infusion.
return
$this
;
}
/**
* Check if this checkbox is indeterminate.
*
* @return bool Checkbox is indeterminate
*/
public
function
isIndeterminate
()
{
return
$this
->
indeterminate
;
}
/** @inheritDoc */
public
function
getConfig
(
&
$config
)
{
if
(
$this
->
selected
)
{
$config
[
'selected'
]
=
$this
->
selected
;
}
if
(
$this
->
indeterminate
)
{
$config
[
'indeterminate'
]
=
$this
->
indeterminate
;
}
return
parent
::
getConfig
(
$config
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 16, 20:51 (1 d, 11 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
28/5f/7ff8c90a9b0f0a9a07a5683f4b58
Default Alt Text
CheckboxInputWidget.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment