Skip to content

Commit a2327c9

Browse files
fixed clearing form after saving with error
1 parent 65da3e6 commit a2327c9

File tree

1 file changed

+34
-26
lines changed

1 file changed

+34
-26
lines changed

app/code/Magento/Cms/Model/Page/DataProvider.php

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Cms\Model\Page;
77

8+
use Magento\Cms\Api\Data\PageInterface;
89
use Magento\Cms\Api\PageRepositoryInterface;
910
use Magento\Cms\Model\Page;
1011
use Magento\Cms\Model\ResourceModel\Page\CollectionFactory;
@@ -122,46 +123,53 @@ public function getData()
122123
return $this->loadedData;
123124
}
124125

125-
try {
126-
$page = $this->getCurrentPage();
127-
} catch (LocalizedException $exception) {
128-
return [];
129-
}
130-
131-
$pageId = $page->getId();
132-
$this->loadedData[$pageId] = $page->getData();
126+
$page = $this->getCurrentPage();
127+
$this->loadedData[$page->getId()] = $page->getData();
133128
if ($page->getCustomLayoutUpdateXml() || $page->getLayoutUpdateXml()) {
134129
//Deprecated layout update exists.
135-
$this->loadedData[$pageId]['layout_update_selected'] = '_existing_';
130+
$this->loadedData[$page->getId()]['layout_update_selected'] = '_existing_';
136131
}
137132

138-
$data = $this->dataPersistor->get('cms_page');
139-
if (empty($data)) {
140-
return $this->loadedData;
133+
return $this->loadedData;
134+
}
135+
136+
/**
137+
* Return current page
138+
*
139+
* @return PageInterface
140+
*/
141+
private function getCurrentPage(): PageInterface
142+
{
143+
$newPage = $this->collection->getNewEmptyItem();
144+
$pageId = $this->getPageId();
145+
if ($pageId) {
146+
try {
147+
$page = $this->pageRepository->getById($pageId);
148+
} catch (LocalizedException $exception) {
149+
$page = $newPage;
150+
}
151+
152+
return $page;
141153
}
142154

143-
$page = $this->collection->getNewEmptyItem();
144-
$page->setData($data);
145-
$this->loadedData[$pageId] = $page->getData();
146-
if ($page->getCustomLayoutUpdateXml() || $page->getLayoutUpdateXml()) {
147-
$this->loadedData[$pageId]['layout_update_selected'] = '_existing_';
155+
$data = $this->dataPersistor->get('cms_page');
156+
if (empty($data)) {
157+
return $newPage;
148158
}
149159
$this->dataPersistor->clear('cms_page');
160+
$page = $newPage->setData($data);
150161

151-
return $this->loadedData;
162+
return $page;
152163
}
153164

154165
/**
155-
* Loads the current page by current request params.
166+
* Returns current page id from request
156167
*
157-
* @return Page
158-
* @throws LocalizedException
168+
* @return int
159169
*/
160-
private function getCurrentPage(): Page
170+
private function getPageId(): int
161171
{
162-
$pageId = $this->request->getParam($this->getRequestFieldName(), 0);
163-
164-
return $this->pageRepository->getById($pageId);
172+
return (int) $this->request->getParam($this->getRequestFieldName());
165173
}
166174

167175
/**
@@ -200,7 +208,7 @@ public function getMeta()
200208

201209
$page = null;
202210
try {
203-
$page = $this->getCurrentPage();
211+
$page = $this->pageRepository->getById($this->getPageId());
204212
} catch (LocalizedException $e) {
205213
$this->logger->error($e->getMessage());
206214
}

0 commit comments

Comments
 (0)