Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F6045993
RequiredElement.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
RequiredElement.php
View Options
<?php
namespace
OOUI
;
/**
* Element with a required attribute.
*
* @abstract
*/
trait
RequiredElement
{
/**
* Mark as required.
*
* @var bool
*/
protected
$required
=
false
;
/**
* @var Element
*/
protected
$requiredElement
;
/**
* @var IndicatorElement|null
*/
protected
$indicatorElement
;
/**
* @var Element|null
*/
protected
$input
;
/**
* @param array $config Configuration options
* - bool $config['required'] Mark the field as required.
* Implies `indicator: 'required'`. Note that `false` & setting `indicator: 'required'
* will result in no indicator shown. (default: false)
* - Element $config['requiredElement']
* - IndicatorElement $config['indicatorElement']
*/
public
function
initializeRequiredElement
(
array
$config
=
[]
)
{
// Properties
$this
->
requiredElement
=
$config
[
'requiredElement'
]
??
(
$this
->
input
??
$this
);
$this
->
indicatorElement
=
array_key_exists
(
'indicatorElement'
,
$config
)
?
$config
[
'indicatorElement'
]
:
$this
;
if
(
$this
->
indicatorElement
&&
!
method_exists
(
$this
->
indicatorElement
,
'getIndicator'
)
)
{
throw
new
Exception
(
'config[
\'
indicatorElement
\'
] must use the IndicatorElement trait.'
);
}
// Initialization
$this
->
setRequired
(
$config
[
'required'
]
??
false
);
$this
->
registerConfigCallback
(
function
(
&
$config
)
{
$config
[
'required'
]
=
$this
->
required
;
}
);
}
/**
* Check if the widget is required.
*
* @return bool
*/
public
function
isRequired
():
bool
{
return
$this
->
required
;
}
/**
* Set the required state of the widget.
*
* @param bool $state Make input required
* @return $this
*/
public
function
setRequired
(
bool
$state
)
{
$this
->
required
=
$state
;
if
(
$this
->
required
)
{
$this
->
requiredElement
->
setAttributes
(
[
'required'
=>
null
]
);
if
(
$this
->
indicatorElement
&&
$this
->
indicatorElement
->
getIndicator
()
===
null
)
{
$this
->
indicatorElement
->
setIndicator
(
'required'
);
}
}
else
{
$this
->
requiredElement
->
removeAttributes
(
[
'required'
]
);
if
(
$this
->
indicatorElement
&&
$this
->
indicatorElement
->
getIndicator
()
===
'required'
)
{
$this
->
indicatorElement
->
setIndicator
(
null
);
}
}
return
$this
;
}
/**
* @param callable $func
*/
abstract
public
function
registerConfigCallback
(
callable
$func
);
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Oct 4 2026, 21:49 (5 w, 5 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
07/18/c8b444bfc0dea5c666566e3a7747
Default Alt Text
RequiredElement.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment