Skip to content

Commit 0749d01

Browse files
author
Ben Thomson
authoredApr 4, 2020
Fix form widget aliases (#421)
Fixes #419 & octobercms/october#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
1 parent 095fdae commit 0749d01

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed
 

‎controllers/Index.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public function onUpdatePageLayout()
274274

275275
$object = $this->fillObjectFromPost($type);
276276

277-
return $this->pushObjectForm($type, $object);
277+
return $this->pushObjectForm($type, $object, Request::input('formWidgetAlias'));
278278
}
279279

280280
public function onGetInspectorConfiguration()
@@ -542,7 +542,7 @@ protected function makeObjectFormWidget($type, $object, $alias = null)
542542

543543
$widgetConfig = $this->makeConfig($formConfigs[$type]);
544544
$widgetConfig->model = $object;
545-
$widgetConfig->alias = $alias ?: 'form'.studly_case($type).md5($object->exists ? $object->getFileName() : uniqid());
545+
$widgetConfig->alias = $alias ?: 'form' . studly_case($type) . md5($object->exists ? $object->getFileName() : uniqid());
546546
$widgetConfig->context = !$object->exists ? 'create' : 'update';
547547

548548
$widget = $this->makeWidget('Backend\Widgets\Form', $widgetConfig);
@@ -693,7 +693,7 @@ protected function fillObjectFromPost($type)
693693
{
694694
$objectPath = trim(Request::input('objectPath'));
695695
$object = $objectPath ? $this->loadObject($type, $objectPath) : $this->createObject($type);
696-
$formWidget = $this->makeObjectFormWidget($type, $object);
696+
$formWidget = $this->makeObjectFormWidget($type, $object, Request::input('formWidgetAlias'));
697697

698698
$saveData = $formWidget->getSaveData();
699699
$postData = post();
@@ -771,9 +771,9 @@ protected function fillObjectFromPost($type)
771771
return $object;
772772
}
773773

774-
protected function pushObjectForm($type, $object)
774+
protected function pushObjectForm($type, $object, $alias = null)
775775
{
776-
$widget = $this->makeObjectFormWidget($type, $object);
776+
$widget = $this->makeObjectFormWidget($type, $object, $alias);
777777

778778
$this->vars['canCommit'] = $this->canCommitObject($object);
779779
$this->vars['canReset'] = $this->canResetObject($object);

0 commit comments

Comments
 (0)
Please sign in to comment.