88
99namespace Magefan \Blog \Controller \Adminhtml ;
1010
11+ use Magento \Framework \App \Request \DataPersistorInterface ;
12+ use Magento \Backend \App \Action \Context ;
13+
1114/**
1215 * Abstract admin controller
1316 */
@@ -74,6 +77,25 @@ abstract class Actions extends \Magento\Backend\App\Action
7477 */
7578 protected $ _coreRegistry = null ;
7679
80+
81+ /**
82+ * @var DataPersistorInterface
83+ */
84+ protected $ dataPersistor ;
85+
86+ /**
87+ * @param Action\Context $context
88+ * @param PostDataProcessor $dataProcessor
89+ * @param DataPersistorInterface $dataPersistor
90+ */
91+ public function __construct (
92+ Context $ context ,
93+ DataPersistorInterface $ dataPersistor
94+ ) {
95+ $ this ->dataPersistor = $ dataPersistor ;
96+ parent ::__construct ($ context );
97+ }
98+
7799 /**
78100 * Action execute
79101 * @return \Magento\Framework\Controller\ResultInterface
@@ -195,6 +217,8 @@ public function _saveAction()
195217
196218 try {
197219 $ params = $ this ->_paramsHolder ? $ request ->getParam ($ this ->_paramsHolder ) : $ request ->getParams ();
220+ $ params = $ this ->filterParams ($ params );
221+
198222 $ idFieldName = $ model ->getResource ()->getIdFieldName ();
199223 if (isset ($ params [$ idFieldName ]) && empty ($ params [$ idFieldName ])) {
200224 unset($ params [$ idFieldName ]);
@@ -209,7 +233,7 @@ public function _saveAction()
209233 $ this ->_setFormData (false );
210234 } catch (\Magento \Framework \Exception \LocalizedException $ e ) {
211235 $ this ->messageManager ->addError (nl2br ($ e ->getMessage ()));
212- $ this ->_setFormData ();
236+ $ this ->_setFormData ($ params );
213237 } catch (\Exception $ e ) {
214238 $ this ->messageManager ->addException (
215239 $ e ,
@@ -218,7 +242,7 @@ public function _saveAction()
218242 $ e ->getMessage ()
219243 )
220244 );
221- $ this ->_setFormData ();
245+ $ this ->_setFormData ($ params );
222246 }
223247
224248 $ hasError = (bool )$ this ->messageManager ->getMessages ()->getCountByType (
@@ -413,12 +437,32 @@ protected function _configAction()
413437 */
414438 protected function _setFormData ($ data = null )
415439 {
416- $ this ->_getSession ()->setData ($ this ->_formSessionKey ,
417- is_null ($ data ) ? $ this ->getRequest ()->getParams () : $ data );
440+ if (null === $ data ) {
441+ $ data = $ this ->getRequest ()->getParams ();
442+ }
443+
444+ if (false === $ data ) {
445+ $ this ->dataPersistor ->clear ($ this ->_formSessionKey );
446+ } else {
447+ $ this ->dataPersistor ->set ($ this ->_formSessionKey , $ data );
448+ }
449+
450+ /* deprecated save in session */
451+ $ this ->_getSession ()->setData ($ this ->_formSessionKey , $ data );
418452
419453 return $ this ;
420454 }
421455
456+ /**
457+ * Filter request params
458+ * @param array $data
459+ * @return array
460+ */
461+ protected function filterParams ($ data )
462+ {
463+ return $ data ;
464+ }
465+
422466 /**
423467 * Get core registry
424468 * @return void
0 commit comments