Simplified switch and check for boolean

This commit is contained in:
simialbi 2021-11-25 10:18:23 +01:00 committed by GitHub
parent 1e7013c360
commit 6eff0f80ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -269,22 +269,25 @@ class ActiveField extends \yii\widgets\ActiveField
Html::removeCssClass($options, 'form-control');
$this->labelOptions = ArrayHelper::merge($this->labelOptions, $labelOptions);
$this->wrapperOptions = ArrayHelper::merge($this->wrapperOptions, $wrapperOptions);
$switch = isset($options['switch']) && $options['switch'];
if (!empty($options['switch'])) {
if ($switch) {
$this->addRoleAttributes($options, 'switch');
}
if (!isset($options['template'])) {
if (empty($options['switch'])) {
$this->template = $enclosedByLabel ? $this->checkEnclosedTemplate : $this->checkTemplate;
} else {
if ($switch) {
$this->template = $enclosedByLabel ? $this->switchEnclosedTemplate : $this->switchTemplate;
} else {
$this->template = $enclosedByLabel ? $this->checkEnclosedTemplate : $this->checkTemplate;
}
} else {
$this->template = $options['template'];
}
if ($this->form->layout === ActiveForm::LAYOUT_HORIZONTAL) {
if (!isset($options['template'])) {
$this->template = empty($options['switch']) ? $this->checkHorizontalTemplate : $this->switchHorizontalTemplate;
$this->template = ($switch)
? $this->switchHorizontalTemplate
: $this->checkHorizontalTemplate;
}
Html::removeCssClass($this->labelOptions, $this->horizontalCssClasses['label']);
Html::addCssClass($this->wrapperOptions, $this->horizontalCssClasses['offset']);