77
88use Magento \Cms \Api \Data \PageInterface ;
99use Magento \Cms \Api \PageRepositoryInterface ;
10- use Magento \Cms \Model \Page ;
10+ use Magento \Cms \Model \PageFactory ;
1111use Magento \Cms \Model \ResourceModel \Page \CollectionFactory ;
1212use Magento \Framework \App \ObjectManager ;
1313use Magento \Framework \App \Request \DataPersistorInterface ;
@@ -53,6 +53,11 @@ class DataProvider extends ModifierPoolDataProvider
5353 */
5454 private $ customLayoutManager ;
5555
56+ /**
57+ * @var PageFactory
58+ */
59+ private $ pageFactory ;
60+
5661 /**
5762 * @var LoggerInterface
5863 */
@@ -71,6 +76,7 @@ class DataProvider extends ModifierPoolDataProvider
7176 * @param RequestInterface|null $request
7277 * @param CustomLayoutManagerInterface|null $customLayoutManager
7378 * @param PageRepositoryInterface|null $pageRepository
79+ * @param PageFactory|null $pageFactory
7480 * @param LoggerInterface|null $logger
7581 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
7682 */
@@ -87,6 +93,7 @@ public function __construct(
8793 ?RequestInterface $ request = null ,
8894 ?CustomLayoutManagerInterface $ customLayoutManager = null ,
8995 ?PageRepositoryInterface $ pageRepository = null ,
96+ ?PageFactory $ pageFactory = null ,
9097 ?LoggerInterface $ logger = null
9198 ) {
9299 parent ::__construct ($ name , $ primaryFieldName , $ requestFieldName , $ meta , $ data , $ pool );
@@ -98,6 +105,7 @@ public function __construct(
98105 $ this ->customLayoutManager = $ customLayoutManager
99106 ?? ObjectManager::getInstance ()->get (CustomLayoutManagerInterface::class);
100107 $ this ->pageRepository = $ pageRepository ?? ObjectManager::getInstance ()->get (PageRepositoryInterface::class);
108+ $ this ->pageFactory = $ pageFactory ?: ObjectManager::getInstance ()->get (PageFactory::class);
101109 $ this ->logger = $ logger ?: ObjectManager::getInstance ()->get (LoggerInterface::class);
102110 }
103111
@@ -140,24 +148,24 @@ public function getData()
140148 */
141149 private function getCurrentPage (): PageInterface
142150 {
143- $ newPage = $ this ->collection ->getNewEmptyItem ();
144151 $ pageId = $ this ->getPageId ();
145152 if ($ pageId ) {
146153 try {
147154 $ page = $ this ->pageRepository ->getById ($ pageId );
148155 } catch (LocalizedException $ exception ) {
149- $ page = $ newPage ;
156+ $ page = $ this -> pageFactory -> create () ;
150157 }
151158
152159 return $ page ;
153160 }
154161
155162 $ data = $ this ->dataPersistor ->get ('cms_page ' );
156163 if (empty ($ data )) {
157- return $ newPage ;
164+ return $ this -> pageFactory -> create () ;
158165 }
159166 $ this ->dataPersistor ->clear ('cms_page ' );
160- $ page = $ newPage ->setData ($ data );
167+ $ page = $ this ->pageFactory ->create ()
168+ ->setData ($ data );
161169
162170 return $ page ;
163171 }
0 commit comments