Пример #1
0
 /**
  * Get image preview url
  *
  * @return string
  */
 protected function _getUrl()
 {
     $url = false;
     if ($this->getValue()) {
         $url = $this->imageModel->getBaseUrl() . $this->getValue();
     }
     return $url;
 }
Пример #2
0
 /**
  * @return mixed
  * @throws \Magento\Framework\Model\Exception
  */
 public function execute()
 {
     $data = $this->getRequest()->getPost('article');
     $resultRedirect = $this->resultRedirectFactory->create();
     if ($data) {
         $data = $this->filterData($data);
         $article = $this->initArticle();
         $article->setData($data);
         $image = $this->uploadModel->uploadFileAndGetName('image', $this->imageModel->getBaseDir(), $data);
         $article->setImage($image);
         $file = $this->uploadModel->uploadFileAndGetName('file', $this->fileModel->getBaseDir(), $data);
         $article->setFile($file);
         $products = $this->getRequest()->getPost('products', -1);
         if ($products != -1) {
             $article->setProductsData($this->jsHelper->decodeGridSerializedInput($products));
         }
         $this->_eventManager->dispatch('gemtoo_blog_article_prepare_save', ['article' => $article, 'request' => $this->getRequest()]);
         try {
             $article->save();
             $this->messageManager->addSuccess(__('The article has been saved.'));
             $this->_getSession()->setGemtooBlogArticleData(false);
             if ($this->getRequest()->getParam('back')) {
                 $resultRedirect->setPath('gemtoo_blog/*/edit', ['article_id' => $article->getId(), '_current' => true]);
                 return $resultRedirect;
             }
             $resultRedirect->setPath('gemtoo_blog/*/');
             return $resultRedirect;
         } catch (LocalizedException $e) {
             $this->messageManager->addError($e->getMessage());
         } catch (\RuntimeException $e) {
             $this->messageManager->addError($e->getMessage());
         } catch (\Exception $e) {
             $this->messageManager->addException($e, __('Something went wrong while saving the article.'));
         }
         $this->_getSession()->setGemtooBlogArticleData($data);
         $resultRedirect->setPath('gemtoo_blog/*/edit', ['article_id' => $article->getId(), '_current' => true]);
         return $resultRedirect;
     }
     $resultRedirect->setPath('gemtoo_blog/*/');
     return $resultRedirect;
 }