@@ -111,10 +111,9 @@ public function execute()
111
111
try {
112
112
$ this ->pageRepository ->save ($ model );
113
113
$ this ->messageManager ->addSuccessMessage (__ ('You saved the page. ' ));
114
- $ this ->dataPersistor ->clear ('cms_page ' );
115
- return $ this ->processPageReturn ($ model , $ data , $ resultRedirect );
114
+ return $ this ->processResultRedirect ($ model , $ resultRedirect , $ data );
116
115
} catch (LocalizedException $ e ) {
117
- $ this ->messageManager ->addExceptionMessage ($ e ->getPrevious () ?:$ e );
116
+ $ this ->messageManager ->addExceptionMessage ($ e ->getPrevious () ?: $ e );
118
117
} catch (\Exception $ e ) {
119
118
$ this ->messageManager ->addExceptionMessage ($ e , __ ('Something went wrong while saving the page. ' ));
120
119
}
@@ -126,37 +125,36 @@ public function execute()
126
125
}
127
126
128
127
/**
129
- * Process and set the page return
128
+ * Process result redirect
130
129
*
131
- * @param \Magento\Cms\Model\Block $model
130
+ * @param \Magento\Cms\Api\Data\PageInterface $model
131
+ * @param \Magento\Backend\Model\View\Result\Redirect $resultRedirect
132
132
* @param array $data
133
- * @param \Magento\Framework\Controller\ResultInterface $resultRedirect
134
- * @return \Magento\Framework\Controller\ResultInterface
133
+ * @return \Magento\Backend\Model\View\Result\Redirect
134
+ * @throws LocalizedException
135
135
*/
136
- private function processPageReturn ($ model , $ data , $ resultRedirect )
136
+ private function processResultRedirect ($ model , $ resultRedirect , $ data )
137
137
{
138
- $ redirect = $ data ['back ' ] ?? 'close ' ;
139
-
140
- if ($ redirect === 'duplicate ' ) {
138
+ if ($ this ->getRequest ()->getParam ('back ' , false ) === 'duplicate ' ) {
141
139
$ newPage = $ this ->pageFactory ->create (['data ' => $ data ]);
142
140
$ newPage ->setId (null );
143
- $ identifier = $ newPage ->getIdentifier () . '- ' . uniqid ();
141
+ $ identifier = $ model ->getIdentifier () . '- ' . uniqid ();
144
142
$ newPage ->setIdentifier ($ identifier );
145
143
$ newPage ->setIsActive (false );
146
144
$ this ->pageRepository ->save ($ newPage );
147
145
$ this ->messageManager ->addSuccessMessage (__ ('You duplicated the page. ' ));
148
- $ resultRedirect ->setPath (
146
+ return $ resultRedirect ->setPath (
149
147
'*/*/edit ' ,
150
148
[
151
149
'page_id ' => $ newPage ->getId (),
152
150
'_current ' => true
153
151
]
154
152
);
155
- } else if ($ redirect === 'continue ' ) {
156
- $ resultRedirect ->setPath ('*/*/edit ' , ['page_id ' => $ model ->getId (), '_current ' => true ]);
157
- } else if ($ redirect === 'close ' ) {
158
- $ resultRedirect ->setPath ('*/*/ ' );
159
153
}
160
- return $ resultRedirect ;
154
+ $ this ->dataPersistor ->clear ('cms_page ' );
155
+ if ($ this ->getRequest ()->getParam ('back ' )) {
156
+ return $ resultRedirect ->setPath ('*/*/edit ' , ['page_id ' => $ model ->getId (), '_current ' => true ]);
157
+ }
158
+ return $ resultRedirect ->setPath ('*/*/ ' );
161
159
}
162
160
}
0 commit comments