From 0749d01fc7f3d5f663bea96e8b6ccac06fb3844a Mon Sep 17 00:00:00 2001 From: Ben Thomson Date: Sat, 4 Apr 2020 16:05:44 +0800 Subject: [PATCH] Fix form widget aliases (#421) Fixes #419 & https://github.com/octobercms/october/issues/4628 - Create a unique alias if the object is new - ie. new page or menu - Ensure widget alias is kept in between refreshes and AJAX requests --- controllers/Index.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/controllers/Index.php b/controllers/Index.php index 50f384ea..e0ebc482 100644 --- a/controllers/Index.php +++ b/controllers/Index.php @@ -274,7 +274,7 @@ public function onUpdatePageLayout() $object = $this->fillObjectFromPost($type); - return $this->pushObjectForm($type, $object); + return $this->pushObjectForm($type, $object, Request::input('formWidgetAlias')); } public function onGetInspectorConfiguration() @@ -542,7 +542,7 @@ protected function makeObjectFormWidget($type, $object, $alias = null) $widgetConfig = $this->makeConfig($formConfigs[$type]); $widgetConfig->model = $object; - $widgetConfig->alias = $alias ?: 'form'.studly_case($type).md5($object->exists ? $object->getFileName() : uniqid()); + $widgetConfig->alias = $alias ?: 'form' . studly_case($type) . md5($object->exists ? $object->getFileName() : uniqid()); $widgetConfig->context = !$object->exists ? 'create' : 'update'; $widget = $this->makeWidget('Backend\Widgets\Form', $widgetConfig); @@ -693,7 +693,7 @@ protected function fillObjectFromPost($type) { $objectPath = trim(Request::input('objectPath')); $object = $objectPath ? $this->loadObject($type, $objectPath) : $this->createObject($type); - $formWidget = $this->makeObjectFormWidget($type, $object); + $formWidget = $this->makeObjectFormWidget($type, $object, Request::input('formWidgetAlias')); $saveData = $formWidget->getSaveData(); $postData = post(); @@ -771,9 +771,9 @@ protected function fillObjectFromPost($type) return $object; } - protected function pushObjectForm($type, $object) + protected function pushObjectForm($type, $object, $alias = null) { - $widget = $this->makeObjectFormWidget($type, $object); + $widget = $this->makeObjectFormWidget($type, $object, $alias); $this->vars['canCommit'] = $this->canCommitObject($object); $this->vars['canReset'] = $this->canResetObject($object);