You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<?php
/**
* Field to render a checkbox as a switch with left and right option text.
*/
class SwitchField extends CompositeField {
public function __construct($checkboxField, $leftOption, $rightOption) {
$this->checkboxField = $checkboxField;
$this->leftOption = $leftOption;
$this->rightOption = $rightOption;
if(!$this->checkboxField instanceof CheckboxField){
throw new Exception('First parameter of SwitchField must be an instance of CheckboxField');
}
parent::__construct(array($checkboxField, $leftOption, $rightOption));
}
}
Example usage
$checkbox = new CheckboxField("Test", "Test", true);
$fields->addFieldToTab(
'Root.Test',
new SwitchField(
$checkbox,
new LiteralField("TestLeft","TestLeft"),
new LiteralField("TestRight","TestRight")
)
);
Note: switchfield may require overriding Fieldlist to render in template properly