/** * Extend ActiveField with any other generic settings ahead of rendering it * * @param ActiveField $field * @param string $type * @param array $params array of params for the field type call * @param string $label * @param string $hint * @param array $icon * @param array $tooltip * @param array $addon * @param false|array $allowClear * @return ActiveField */ private function getInput($field, $type, $params = null, $label = null, $hint = null, $icon = null, $tooltip = null, $addon = null, $allowClear = null) { $field->setType($type); if ($label !== null && $label !== false) { $field = $field->label($label); } if ($hint !== null && $hint !== false) { $field = $field->hint($hint); } if ($icon !== null && $icon !== false || $tooltip !== null && $tooltip !== false) { $field->icon($icon, $tooltip); } if ($addon !== null && is_array($addon)) { $field->mergeAddon($addon); } if ($allowClear !== null && is_array($allowClear) && $allowClear) { $inputClearType = ArrayHelper::remove($allowClear, 'input', 'input'); $inputClearValue = ArrayHelper::remove($allowClear, 'value', ''); $inputClearGroupSize = ArrayHelper::remove($allowClear, 'size', ''); $field->addClearAddOn($inputClearType, $inputClearValue, $inputClearGroupSize); } if ($params !== null) { $field = call_user_func_array([$field, $type], $params); } return $field; }
/** * Initializes the widget. * This renders the form open tag. */ public function init() { if (!isset($this->options['id'])) { $this->options['id'] = $this->getId(); } if ($this->defaultClass) { Html::addCssClass($this->options, $this->defaultClass); } if ($this->ajax) { Html::addCssClass($this->options, 'ajaxform'); } switch ($this->type) { case self::TYPE_HORIZONTAL: if ($this->stripped) { Html::addCssClass($this->options, 'form-row-stripped'); } if ($this->separated) { Html::addCssClass($this->options, 'form-row-seperated'); } if ($this->bordered) { Html::addCssClass($this->options, 'form-bordered'); } Html::addCssClass($this->options, 'form-horizontal'); $this->fieldConfig = ArrayHelper::merge(['labelOptions' => ['class' => 'col-md-' . $this->labelSpan . ' control-label'], 'template' => "{label}\n" . Html::tag('div', "{input}\n{hint}\n{error}", ['class' => 'col-md-' . ($this->fullSpan - $this->labelSpan)])], $this->fieldConfig); if (false) { // wlchere - need to play with this once we know how the templates work out perhaps this needs to be an active field thing // only useful because the hint and error blocks take up space even when no error or hint exists $this->fieldConfig['template'] = str_replace("\n{error}", '', $this->fieldConfig['template']); } break; case self::TYPE_INLINE: Html::addCssClass($this->options, 'form-inline'); $this->fieldConfig = ArrayHelper::merge(['labelOptions' => ['class' => 'sr-only']], $this->fieldConfig); break; } if (!isset($this->fieldConfig['class'])) { $this->fieldConfig['class'] = ActiveField::className(); } if ($this->fake) { echo Html::beginTag('div', $this->options); } else { echo Html::beginForm($this->action, $this->method, $this->options); } echo $this->renderActions(self::BUTTONS_POSITION_TOP); echo Html::beginTag('div', ['class' => 'form-body']); }