/** * @return string */ protected function getContent() { $hiddenInputs = []; foreach ($this->hiddenInputs as $name => $value) { $hiddenInputs[] = \mpf\web\helpers\Form::get()->hiddenInput($name, $value); } $hiddenInputs = implode("\n", $hiddenInputs); $fields = array(); foreach ($this->fields as $field) { if (is_string($field)) { $field = new fields\Text(array('name' => $field)); $fields[] = $field->display($this); } elseif (is_array($field)) { $class = isset($field['type']) ? ucfirst($field['type']) : 'Text'; $class = false === strpos($class, '\\') ? '\\mpf\\widgets\\form\\fields\\' . $class : $class; unset($field['type']); $field = new $class($field); /* @var $field \mpf\widgets\form\Field */ $fields[] = $field->display($this); } } $buttons = []; if ($this->submitButton) { $buttons[] = $this->getButton(is_array($this->submitButton) ? $this->submitButton : ['name' => $this->name, 'label' => $this->submitButton]); } else { $buttons[] = $this->getButton($this->name); } foreach ($this->buttons as $button) { $buttons[] = $this->getButton($button); } if (!isset($this->buttonsRowHtmlOptions['class'])) { $this->buttonsRowHtmlOptions['class'] = 'row-buttons'; } $links = []; foreach ($this->links as $label => $link) { if (is_array($link)) { $links[] = Html::get()->link($link['href'], $label, $link); } else { $links[] = Html::get()->link($link, $this->translate($label)); } } $links = implode(' ', $links); return $hiddenInputs . implode("\n", $fields) . HtmlHelper::get()->tag('div', $links . implode("\n", $buttons), $this->buttonsRowHtmlOptions); }
/** * @param mixed $value * @param string $key * @param string $baseName * @param array $errors * @return string */ protected function getSingleInput($value, $key, $baseName, $errors = []) { $c = $this->modelClass; $labels = $c::getLabels(); if ($this->multiple) { $baseName .= "[{$key}]"; } $fields = []; foreach ($this->fields as $field) { $sName = $name = is_string($field) ? $field : $field['name']; $label = $this->translate(isset($labels[$name]) ? $labels[$name] : ucwords(str_replace('_', ' ', $name))); $name = $baseName . "[" . $name . "]"; $error = isset($errors[$name]) ? $errors[$name] : false; if (is_string($field)) { $field = new Text(['name' => $name, 'label' => $label, 'value' => isset($value[$sName]) ? $value[$sName] : '', 'error' => $error]); $fields[] = $field->display($this->form); } elseif (is_array($field)) { $class = isset($field['type']) ? ucfirst($field['type']) : 'Text'; $class = false === strpos($class, '\\') ? '\\mpf\\widgets\\form\\fields\\' . $class : $class; unset($field['type']); if (!isset($field['label'])) { $field['label'] = $label; } $field['value'] = isset($value[$sName]) ? $value[$sName] : (isset($field['defaultValue']) ? $field['defaultValue'] : ''); $field['name'] = $name; $field['error'] = $error; $field = new $class($field); /* @var $field \mpf\widgets\form\Field */ $fields[] = $field->display($this->form); } } $r = ($this->legend ? Html::get()->tag('legend', str_replace('_KEY_', $key, $this->legendLabel ?: $this->getLabel())) : '') . implode("\n", $fields); $r .= $this->getButtons(); return Html::get()->tag($this->contentTag, $r); }