prop('required'); if($required === 'auto') { $children = $this->children(); $requiredFields = $this->prop('requiredFields'); if($this->hasProp('name')) $required = isFieldRequired($this->prop('name'), $requiredFields); else if($children) { $required = false; foreach($children as $child) { if($child instanceof node && $child->hasProp('name') && isFieldRequired($child->prop('name'), $requiredFields)) $required = true; } } else $required = false; $this->setProp('required', $required); } } /** * @return \zin\node|\zin\set */ protected function buildLabel() { list($name, $label, $labelFor, $labelClass, $labelProps, $labelHint, $labelHintClass, $labelHintProps, $labelHintIcon, $labelActions, $labelActionsClass, $labelActionsProps, $checkbox, $required, $strong, $labelControl) = $this->prop(array('name', 'label', 'labelFor', 'labelClass', 'labelProps', 'labelHint', 'labelHintClass', 'labelHintProps', 'labelHintIcon', 'labelActions', 'labelActionsClass', 'labelActionsProps', 'checkbox', 'required', 'strong', 'labelControl')); if(is_null($label) || $label === false) return setClass('no-label'); if($labelControl instanceof setting) $labelControl = $labelControl->toArray(); return new formLabel ( set::className($labelClass, $strong ? 'font-bold' : null), set::required($required), set::hint($labelHint), set::hintIcon($labelHintIcon), set::hintClass($labelHintClass), set::hintProps($labelHintProps), set::actions($labelActions), set::actionsClass($labelActionsClass), set::actionsProps($labelActionsProps), set::checkbox($checkbox), set::text($label), set('for', is_null($labelFor) ? $name : $labelFor), set($labelProps), $labelControl ? new content(is_array($labelControl) ? set($labelControl) : $labelControl) : null ); } protected function buildControl() { $control = $this->prop('control'); if($control instanceof node) return $control; if(!is_string($control) && is_callable($control, true)) return $control($this->props->toJSON()); if(is_string($control)) $control = array('control' => $control); elseif($control instanceof item) $control = $control->props->toJSON(); elseif(is_object($control)) $control = get_object_vars($control); elseif(is_null($control) && $this->hasProp('name')) $control = array(); if(!is_array($control)) return null; if($this->hasProp('id') && !isset($control['id'])) $control['id'] = ''; foreach(static::$controlExtendProps as $controlPropName) { $controlPropValue = $this->prop($controlPropName); if($controlPropValue !== null && !isset($control[$controlPropName])) $control[$controlPropName] = $controlPropValue; } if(isset($control['control']) && $control['control'] === 'hidden') { unset($control['control']); $this->isHiddenField = true; return new input(set::type('hidden'), set($control)); } $controlView = new control(set($control)); return $controlView; } protected function buildTip() { list($tip, $tipClass, $tipProps) = $this->prop(array('tip', 'tipClass', 'tipProps')); if(empty($tip)) return null; return div ( setClass('form-tip', $tipClass), set($tipProps), $tip ); } protected function build() { list($name, $labelWidth, $required, $width, $id, $hidden, $foldable, $pinned, $children, $wrapBefore, $wrapAfter, $data) = $this->prop(array('name', 'labelWidth', 'required', 'width', 'id', 'hidden', 'foldable', 'pinned', 'children', 'wrapBefore', 'wrapAfter', 'data')); $control = $this->buildControl(); if($this->isHiddenField) return $control; $content = div ( setClass('form-group', array('required' => $required, 'hidden' => $hidden, 'is-foldable' => $foldable, 'is-pinned' => $pinned)), zui::width($width), setID($id), setData('name', $name), setData($data), setCssVar('form-horz-label-width', $labelWidth), set($this->getRestProps()), $this->buildLabel(), $control, $children, $this->children(), $this->buildTip() ); if($wrapBefore || $wrapAfter) $content = array($content); if($wrapBefore) array_unshift($content, div(setClass('form-grid-wrap'), setData('wrap-before', $name))); if($wrapAfter) array_push($content, div(setClass('form-grid-wrap'), setData('wrap-after', $name))); return $content; } }