mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
When refreshing fields, forceFill is a bit too flaky
- Using a proxy field would populate a relation with an array of attributes, this is not good or consistent. Instead the FormModelSaver trait is used to bring the behavior in line with FormController and others. This should improve consistency in the behavior and developer expectations. - The noticeable difference will be that relations and their values are now set by the postback data where possible. In cases where this is undesirable -- eg: updating a relation triggers proxy fields to update with existing values, when they should seed from the relation instead (desire to lose prior changes) -- the formExtendRefreshData controller override can be used to prune the existing values from the dataset, where they will then be seeded from the model as normal. - Also the $data property is only rebuilt if it differs from the model. Previously it would corrupt the model-based dataset by converting to an array then back to an object. If the two objects are the same, they will be passed by reference and values will replicate this way.
This commit is contained in:
parent
85ca7715f2
commit
f771887ee5
@ -22,6 +22,8 @@ use Exception;
|
||||
*/
|
||||
class Form extends WidgetBase
|
||||
{
|
||||
use \Backend\Traits\FormModelSaver;
|
||||
|
||||
//
|
||||
// Configurable properties
|
||||
//
|
||||
@ -319,12 +321,21 @@ class Form extends WidgetBase
|
||||
$data = $this->getSaveData();
|
||||
}
|
||||
|
||||
if (method_exists($this->model, 'forceFill')) {
|
||||
$this->model->forceFill($data);
|
||||
/*
|
||||
* Fill the model as if it were to be saved
|
||||
*/
|
||||
$this->prepareModelsToSave($this->model, $data);
|
||||
|
||||
/*
|
||||
* Data set differs from model
|
||||
*/
|
||||
if ($this->data !== $this->model) {
|
||||
$this->data = (object) array_merge((array) $this->data, (array) $data);
|
||||
}
|
||||
|
||||
$this->data = (object) array_merge((array) $this->data, (array) $data);
|
||||
|
||||
/*
|
||||
* Set field values from data source
|
||||
*/
|
||||
foreach ($this->allFields as $field) {
|
||||
$field->value = $this->getFieldValue($field);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user