<?php if (count($params) == 0) { print Html::tag('h2', Yii::t('app', 'No configuration items.')); } else { print Html::tag('p', Yii::t('app', 'Click on the titles to expand.')); foreach ($params as $group => $params) { $options = []; /*if ($isFirst) { $options['class'] = 'in'; $isFirst = false; }*/ $itemBody = ''; foreach ($params as $fieldName => $fieldParams) { $itemBody .= ConfigurationUtils::renderField($group, $fieldName, $fieldParams); } $item = ['label' => Inflector::camel2words($group), 'content' => $itemBody, 'contentOptions' => $options]; $items[] = $item; } echo Collapse::widget(['items' => $items]); ?> <div class="form-group"> <div class="col-lg-offset-2 col-lg-10"> <?php echo Html::submitButton(Yii::t('app', 'Save settings'), ['class' => 'btn btn-primary']); ?> </div> </div> <?php
public static function renderField($group, $fieldName, $fieldParams) { $id = $fieldParams['id']; $type = $fieldParams['type']; $value = $fieldParams['value']; $description = $fieldParams['description']; $options = $fieldParams['options']; $fld = $group . '[' . $fieldName . ']'; $html = ''; switch ($type) { case 'text': $html .= self::labelInput($fieldName, $fld, Html::textInput($fld, $value, ['class' => 'form-control'])); $html .= self::hint($description); break; case 'textarea': $html .= self::labelInput($fieldName, $fld, Html::textarea($fld, $value, ['rows' => 5, 'class' => 'form-control', 'hint' => $description])); $html .= ConfigurationUtils::hint($description); break; case 'checkbox': $html .= self::labelInput($fieldName, $fld, Html::checkbox($fld, $value, ['value' => $value == '1' ? '1' : '0', 'class' => 'form-control autoval'])); break; case 'dropdown': $data = explode(",", $options); $data = array_reverse($data); $data[''] = Yii::t('app', 'Select an option...'); $data = array_reverse($data); $data = array_combine($data, $data); $html .= self::labelInput($fieldName, $fld, Html::dropDownList($fld, $value, $data, ['class' => 'form-control'])); break; } return $html; }