filter = $filter; // $this->collectionFactory = $collectionFactory; $this->dataPersistor = $dataPersistor; $this->scopeConfig = $scopeConfig; $this->_escaper = $escaper; $this->_dateFactory = $dateFactory; $this->inlineTranslation = $inlineTranslation; parent::__construct($context); } /** * Save action * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); $data = $this->getRequest()->getPostValue(); if ($data) { $id = $this->getRequest()->getParam('banners_id'); if (isset($data['status']) && $data['status'] === 'true') { $data['status'] = Block::STATUS_ENABLED; } if (empty($data['banners_id'])) { $data['banners_id'] = null; } /** @var \Magento\Cms\Model\Block $model */ $model = $this->_objectManager->create('FME\Banners\Model\Banners')->load($id); if (!$model->getId() && $id) { $this->messageManager->addError(__('This Banner no longer exists.')); return $resultRedirect->setPath('*/*/'); } if (isset($data['bannerimage'][0]['name']) && isset($data['bannerimage'][0]['tmp_name'])) { $data['bannerimage'] ='/banners/'.$data['bannerimage'][0]['name']; } elseif (isset($data['bannerimage'][0]['name']) && !isset($data['image'][0]['tmp_name'])) { $data['bannerimage'] =$data['bannerimage'][0]['name']; } else { $data['bannerimage'] = null; } $model->setData($data); $this->inlineTranslation->suspend(); try { //////////////////// email $model->save(); $this->messageManager->addSuccess(__('Banner Saved successfully')); $this->dataPersistor->clear('fme_banners'); if ($this->getRequest()->getParam('back')) { return $resultRedirect->setPath('*/*/edit', ['banners_id' => $model->getId()]); } return $resultRedirect->setPath('*/*/'); } catch (LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __('Something went wrong while saving the banner.')); } $this->dataPersistor->set('fme_banners', $data); return $resultRedirect->setPath('*/*/edit', ['banners_id' => $this->getRequest()->getParam('banners_id')]); } return $resultRedirect->setPath('*/*/'); } }