From 6e25c5a8d0834aa083455f9f2b7c75b9bda7ff1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20K=C3=BCndig?= Date: Tue, 31 Mar 2020 19:44:13 +0200 Subject: [PATCH] Fix saving of translations in relation controller by re-using the form widget's model (#4822) This PR is an addition to https://github.com/octobercms/october/pull/4193 Re-using the pivotWidget's and manageWidget's models for saving form data fixes https://github.com/rainlab/translate-plugin/issues/209, where translations are not saved for the model when editing it in a relation widget. I did some manual testing with this change and everything was working as expected: Translations are now properly saved when creating or editing related models with pivot data. Creating related models in `single` mode now works as well. Credits to @alxy for his previous work on this issue! --- modules/backend/behaviors/RelationController.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/backend/behaviors/RelationController.php b/modules/backend/behaviors/RelationController.php index 25d6d3dc2..43d926df6 100644 --- a/modules/backend/behaviors/RelationController.php +++ b/modules/backend/behaviors/RelationController.php @@ -1110,7 +1110,7 @@ class RelationController extends ControllerBehavior $this->relationObject->add($newModel, $sessionKey); } elseif ($this->viewMode == 'single') { - $newModel = $this->viewModel; + $newModel = $this->manageWidget->model; $this->viewWidget->setFormValues($saveData); /* @@ -1154,6 +1154,8 @@ class RelationController extends ControllerBehavior } } elseif ($this->viewMode == 'single') { + $this->viewModel = $this->manageWidget->model; + $this->viewWidget->setFormValues($saveData); $this->viewModel->save(null, $this->manageWidget->getSessionKey()); } @@ -1364,7 +1366,7 @@ class RelationController extends ControllerBehavior $this->beforeAjax(); $foreignKeyName = $this->relationModel->getQualifiedKeyName(); - $hydratedModel = $this->relationObject->where($foreignKeyName, $this->manageId)->first(); + $hydratedModel = $this->pivotWidget->model; $saveData = $this->pivotWidget->getSaveData(); $modelsToSave = $this->prepareModelsToSave($hydratedModel, $saveData);