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'); Html::removeCssClass($options, 'form-control');
$this->labelOptions = ArrayHelper::merge($this->labelOptions, $labelOptions); $this->labelOptions = ArrayHelper::merge($this->labelOptions, $labelOptions);
$this->wrapperOptions = ArrayHelper::merge($this->wrapperOptions, $wrapperOptions); $this->wrapperOptions = ArrayHelper::merge($this->wrapperOptions, $wrapperOptions);
$switch = isset($options['switch']) && $options['switch'];
if (!empty($options['switch'])) { if ($switch) {
$this->addRoleAttributes($options, 'switch'); $this->addRoleAttributes($options, 'switch');
} }
if (!isset($options['template'])) { if (!isset($options['template'])) {
if (empty($options['switch'])) { if ($switch) {
$this->template = $enclosedByLabel ? $this->checkEnclosedTemplate : $this->checkTemplate;
} else {
$this->template = $enclosedByLabel ? $this->switchEnclosedTemplate : $this->switchTemplate; $this->template = $enclosedByLabel ? $this->switchEnclosedTemplate : $this->switchTemplate;
} else {
$this->template = $enclosedByLabel ? $this->checkEnclosedTemplate : $this->checkTemplate;
} }
} else { } else {
$this->template = $options['template']; $this->template = $options['template'];
} }
if ($this->form->layout === ActiveForm::LAYOUT_HORIZONTAL) { if ($this->form->layout === ActiveForm::LAYOUT_HORIZONTAL) {
if (!isset($options['template'])) { 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::removeCssClass($this->labelOptions, $this->horizontalCssClasses['label']);
Html::addCssClass($this->wrapperOptions, $this->horizontalCssClasses['offset']); Html::addCssClass($this->wrapperOptions, $this->horizontalCssClasses['offset']);