Skip to content

Commit

Permalink
Fix form widget aliases (#421)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Ben Thomson authored Apr 4, 2020
1 parent 095fdae commit 0749d01
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions controllers/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0749d01

Please sign in to comment.