formField = $formField; $this->fieldName = $formField->fieldName; $this->valueFrom = $formField->valueFrom; $this->config = $this->makeConfig($configuration); $this->fillFromConfig([ 'model', 'data', 'sessionKey', 'previewMode', 'showLabels' ]); parent::__construct($controller, $configuration); } /** * Returns a unique ID for this widget. Useful in creating HTML markup. */ public function getId($suffix = null) { $id = parent::getId($suffix); $id .= '-' . $this->fieldName; return HtmlHelper::nameToId($id); } /** * Process the postback value for this widget. * @param $value The existing value for this widget. * @return string The new value for this widget. */ public function getSaveValue($value) { return $value; } /** * Returns the value for this form field, * supports nesting via HTML array. * @return string */ public function getLoadValue() { $defaultValue = null; if (!$this->model->exists) { if ($this->formField->defaultFrom) { list($model, $attribute) = $this->formField->resolveModelAttribute($this->model, $this->formField->defaultFrom); $defaultValue = $model->{$attribute}; } elseif ($this->formField->defaults !== '') { $defaultValue = $this->formField->defaults; } } return $this->formField->getValueFromData($this->data ?: $this->model, $defaultValue); } /** * Returns the final model and attribute name of * a nested HTML array attribute. * Eg: list($model, $attribute) = $this->resolveModelAttribute($this->valueFrom); * @param string $attribute. * @return array */ public function resolveModelAttribute($attribute) { return $this->formField->resolveModelAttribute($this->model, $attribute); } }