/** * Renders raw active input based on the attribute settings * * @param \kartik\form\ActiveForm $form the form instance * @param \yii\db\ActiveRecord|\yii\base\Model $model * @param string $attribute the name of the attribute * @param array $settings the attribute settings * * @return \kartik\form\ActiveField * @throws \yii\base\InvalidConfigException * */ protected static function renderRawActiveInput($form, $model, $attribute, $settings) { $type = ArrayHelper::getValue($settings, 'type', self::INPUT_TEXT); $i = strpos($attribute, ']'); $attribName = $i > 0 ? substr($attribute, $i + 1) : $attribute; if (!in_array($type, static::$_validInputs)) { throw new InvalidConfigException("Invalid input type '{$type}' configured for the attribute '{$attribName}'.'"); } $fieldConfig = ArrayHelper::getValue($settings, 'fieldConfig', []); $options = ArrayHelper::getValue($settings, 'options', []); $label = ArrayHelper::getValue($settings, 'label', null); $hint = ArrayHelper::getValue($settings, 'hint', null); $field = $form->field($model, $attribute, $fieldConfig); if ($type === self::INPUT_TEXT || $type === self::INPUT_PASSWORD || $type === self::INPUT_TEXTAREA || $type === self::INPUT_FILE || $type === self::INPUT_HIDDEN || $type === self::INPUT_STATIC) { return static::getInput($field->{$type}($options), $label, $hint); } if ($type === self::INPUT_DROPDOWN_LIST || $type === self::INPUT_LIST_BOX || $type === self::INPUT_CHECKBOX_LIST || $type === self::INPUT_RADIO_LIST || $type === self::INPUT_MULTISELECT) { if (!isset($settings['items'])) { throw new InvalidConfigException("You must setup the 'items' array for attribute '{$attribName}' since it is a '{$type}'."); } return static::getInput($field->{$type}($settings['items'], $options), $label, $hint); } if ($type === self::INPUT_CHECKBOX || $type === self::INPUT_RADIO) { $enclosedByLabel = ArrayHelper::getValue($settings, 'enclosedByLabel', true); if ($label !== null) { $options['label'] = $label; } return static::getInput($field->{$type}($options, $enclosedByLabel), null, $hint); } if ($type === self::INPUT_HTML5) { $html5type = ArrayHelper::getValue($settings, 'html5type', 'text'); return static::getInput($field->{$type}($html5type, $options), $label, $hint); } if ($type === self::INPUT_WIDGET) { $widgetClass = ArrayHelper::getValue($settings, 'widgetClass', []); if (empty($widgetClass) && !$widgetClass instanceof yii\widgets\InputWidget) { throw new InvalidConfigException("A valid 'widgetClass' for '{$attribute}' must be setup and extend from 'yii\\widgets\\InputWidget'."); } return static::getInput($field->{$type}($widgetClass, $options), $label, $hint); } if ($type === self::INPUT_RAW) { return ArrayHelper::getValue($settings, 'value', ''); } }