7
7
8
8
use Magento \Cms \Api \Data \PageInterface ;
9
9
use Magento \Cms \Api \PageRepositoryInterface ;
10
- use Magento \Cms \Model \Page ;
10
+ use Magento \Cms \Model \PageFactory ;
11
11
use Magento \Cms \Model \ResourceModel \Page \CollectionFactory ;
12
12
use Magento \Framework \App \ObjectManager ;
13
13
use Magento \Framework \App \Request \DataPersistorInterface ;
@@ -53,6 +53,11 @@ class DataProvider extends ModifierPoolDataProvider
53
53
*/
54
54
private $ customLayoutManager ;
55
55
56
+ /**
57
+ * @var PageFactory
58
+ */
59
+ private $ pageFactory ;
60
+
56
61
/**
57
62
* @var LoggerInterface
58
63
*/
@@ -71,6 +76,7 @@ class DataProvider extends ModifierPoolDataProvider
71
76
* @param RequestInterface|null $request
72
77
* @param CustomLayoutManagerInterface|null $customLayoutManager
73
78
* @param PageRepositoryInterface|null $pageRepository
79
+ * @param PageFactory|null $pageFactory
74
80
* @param LoggerInterface|null $logger
75
81
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
76
82
*/
@@ -87,6 +93,7 @@ public function __construct(
87
93
?RequestInterface $ request = null ,
88
94
?CustomLayoutManagerInterface $ customLayoutManager = null ,
89
95
?PageRepositoryInterface $ pageRepository = null ,
96
+ ?PageFactory $ pageFactory = null ,
90
97
?LoggerInterface $ logger = null
91
98
) {
92
99
parent ::__construct ($ name , $ primaryFieldName , $ requestFieldName , $ meta , $ data , $ pool );
@@ -98,6 +105,7 @@ public function __construct(
98
105
$ this ->customLayoutManager = $ customLayoutManager
99
106
?? ObjectManager::getInstance ()->get (CustomLayoutManagerInterface::class);
100
107
$ this ->pageRepository = $ pageRepository ?? ObjectManager::getInstance ()->get (PageRepositoryInterface::class);
108
+ $ this ->pageFactory = $ pageFactory ?: ObjectManager::getInstance ()->get (PageFactory::class);
101
109
$ this ->logger = $ logger ?: ObjectManager::getInstance ()->get (LoggerInterface::class);
102
110
}
103
111
@@ -140,24 +148,24 @@ public function getData()
140
148
*/
141
149
private function getCurrentPage (): PageInterface
142
150
{
143
- $ newPage = $ this ->collection ->getNewEmptyItem ();
144
151
$ pageId = $ this ->getPageId ();
145
152
if ($ pageId ) {
146
153
try {
147
154
$ page = $ this ->pageRepository ->getById ($ pageId );
148
155
} catch (LocalizedException $ exception ) {
149
- $ page = $ newPage ;
156
+ $ page = $ this -> pageFactory -> create () ;
150
157
}
151
158
152
159
return $ page ;
153
160
}
154
161
155
162
$ data = $ this ->dataPersistor ->get ('cms_page ' );
156
163
if (empty ($ data )) {
157
- return $ newPage ;
164
+ return $ this -> pageFactory -> create () ;
158
165
}
159
166
$ this ->dataPersistor ->clear ('cms_page ' );
160
- $ page = $ newPage ->setData ($ data );
167
+ $ page = $ this ->pageFactory ->create ()
168
+ ->setData ($ data );
161
169
162
170
return $ page ;
163
171
}
0 commit comments