FieldTimeWithUnits.php (mrbs-1.9.4) | : | FieldTimeWithUnits.php (mrbs-1.10.0) | ||
---|---|---|---|---|
<?php | <?php | |||
namespace MRBS\Form; | namespace MRBS\Form; | |||
use function MRBS\toTimeString; | ||||
class FieldTimeWithUnits extends FieldDiv | class FieldTimeWithUnits extends FieldDiv | |||
{ | { | |||
// Constructs a field that has an enabling checkbox and then inputs for | // Constructs a field that has an enabling checkbox and then inputs for | |||
// the quantity and units of time. | // the quantity and units of time. | |||
// | // | |||
// $param_names An array of the parameter names, indexed by | // $param_names An array of the parameter names, indexed by | |||
// 'enabler', 'quantity' and 'seconds' | // 'enabler', 'quantity' and 'seconds' | |||
// $enabled The current value of the enabling checkbox | // $enabled The current value of the enabling checkbox | |||
// $seconds The current value of the field, in seconds | // $seconds The current value of the field, in seconds | |||
// $suffix Optional text that can appear after the units | // $suffix Optional text that can appear after the units | |||
// $input_attributes Optional array of additional attributes for the input | // $input_attributes Optional array of additional attributes for the input | |||
public function __construct(array $param_names, $enabled, $seconds, $suffix=nu ll, $input_attributes=null) | public function __construct(array $param_names, $enabled, $seconds, $suffix=nu ll, ?array $input_attributes=null) | |||
{ | { | |||
// We can get rid of the assert when the minimum PHP version is 7.1 or great | ||||
er and | ||||
// we can use a nullable type | ||||
assert(is_null($input_attributes) || is_array($input_attributes), | ||||
'$input_attributes must be null or an array'); | ||||
parent::__construct(); | parent::__construct(); | |||
// Convert the raw seconds into as large a unit as possible | // Convert the raw seconds into as large a unit as possible | |||
$duration = $seconds; | $duration = $seconds; | |||
\MRBS\toTimeString($duration, $units); | toTimeString($duration, $units); | |||
// The checkbox, which enables or disables the field | // The checkbox, which enables or disables the field | |||
$checkbox = new ElementInputCheckbox(); | $checkbox = new ElementInputCheckbox(); | |||
$checkbox->setAttributes(array('name' => $param_names['enabler'], | $checkbox->setAttributes(array('name' => $param_names['enabler'], | |||
'class' => 'enabler')) | 'class' => 'enabler')) | |||
->setChecked($enabled); | ->setChecked($enabled); | |||
$this->addControlElement($checkbox); | $this->addControlElement($checkbox); | |||
// The quantity element | // The quantity element | |||
$input = new ElementInputNumber(); | $input = new ElementInputNumber(); | |||
End of changes. 4 change blocks. | ||||
8 lines changed or deleted | 4 lines changed or added |