kartik\builder\BaseForm::renderRawInput PHP Method

renderRawInput() protected static method

Renders raw form input based on the attribute settings.
protected static renderRawInput ( string $attribute, string &$id, array $settings = [] ) : string
$attribute string the name of the attribute.
$id string the input identifier.
$settings array the attribute settings.
return string the form input markup.
    protected static function renderRawInput($attribute, &$id, $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}'.'");
        }
        $value = ArrayHelper::getValue($settings, 'value', null);
        $options = ArrayHelper::getValue($settings, 'options', []);
        $id = str_replace(['[]', '][', '[', ']', ' '], ['', '-', '-', '', '-'], $attribute);
        $id = strtolower($id);
        if ($type === self::INPUT_WIDGET) {
            $id = empty($options['options']['id']) ? $id : $options['options']['id'];
            $options['options']['id'] = $id;
        } else {
            $id = empty($options['id']) ? $id : $options['id'];
            $options['id'] = $id;
        }
        if ($type === self::INPUT_STATIC || $type === self::INPUT_HIDDEN_STATIC) {
            $opts = $options;
            if ($type === self::INPUT_HIDDEN_STATIC) {
                $opts = ArrayHelper::getValue($settings, 'hiddenStaticOptions', []);
            }
            Html::addCssClass($opts, 'form-control-static');
            $out = Html::tag('p', $value, $opts);
            if ($type === self::INPUT_HIDDEN_STATIC) {
                return $out . Html::hiddenInput($attribute, $value, $opts);
            }
            return $out;
        }
        if (!isset($options['class']) && $type !== self::INPUT_CHECKBOX_BUTTON_GROUP && $type !== self::INPUT_RADIO_BUTTON_GROUP) {
            $options['class'] = 'form-control';
        }
        if (isset(static::$_basicInputs[$type])) {
            return Html::$type($attribute, $value, $options);
        }
        if (isset(static::$_dropdownInputs[$type])) {
            if (!isset($settings['items'])) {
                throw new InvalidConfigException("You must setup the 'items' array for attribute '{$attribName}' since it is a '{$type}'.");
            }
            $items = ArrayHelper::getValue($settings, 'items', []);
            return Html::$type($attribute, $value, $items, $options);
        }
        if ($type === self::INPUT_CHECKBOX || $type === self::INPUT_RADIO) {
            $enclosedByLabel = ArrayHelper::getValue($settings, 'enclosedByLabel', true);
            $checked = !empty($value) && $value !== false ? true : false;
            $out = Html::$type($attribute, $checked, $options);
            return $enclosedByLabel ? "<div class='{$type}'>{$out}</div>" : $out;
        }
        if ($type === self::INPUT_HTML5) {
            $html5type = ArrayHelper::getValue($settings, 'html5type', 'text');
            return Html::input($html5type, $attribute, $value, $options);
        }
        if ($type === self::INPUT_WIDGET) {
            $widgetClass = ArrayHelper::getValue($settings, 'widgetClass', []);
            if (empty($widgetClass) && !$widgetClass instanceof InputWidget) {
                throw new InvalidConfigException("A valid 'widgetClass' for '{$attribute}' must be setup and extend from 'yii\\widgets\\InputWidget'.");
            }
            $options['name'] = $attribute;
            $options['value'] = $value;
            return $widgetClass::widget($options);
        }
        if ($type === self::INPUT_RAW) {
            return ArrayHelper::getValue($settings, 'value', '');
        }
        return null;
    }