formField = $formField; $this->fieldName = $formField->fieldName; $this->valueFrom = $formField->valueFrom; $this->config = $this->makeConfig($configuration); $this->fillFromConfig([ 'model', 'data', 'sessionKey', 'previewMode', 'showLabels', 'parentForm', ]); parent::__construct($controller, $configuration); } /** * Retrieve the parent form for this formwidget * * @return Backend\Widgets\Form|null */ public function getParentForm() { return $this->parentForm; } /** * Returns the HTML element field name for this widget, used for capturing * user input, passed back to the getSaveValue method when saving. * @return string HTML element name */ public function getFieldName() { return $this->formField->getName(); } /** * 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. If the value is omitted from * postback data, it will be NULL, otherwise it will be an empty string. * @param mixed $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() { if ($this->formField->value !== null) { return $this->formField->value; } $defaultValue = !$this->model->exists ? $this->formField->getDefaultFromData($this->data ?: $this->model) : null; return $this->formField->getValueFromData($this->data ?: $this->model, $defaultValue); } }