コード例 #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
 /**
  * run the action
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     $data = $this->getRequest()->getPost('post');
     $resultRedirect = $this->resultRedirectFactory->create();
     if ($data) {
         $post = $this->initPost();
         $post->setData($data);
         $image = $this->uploadModel->uploadFileAndGetName('image', $this->imageModel->getBaseDir(), $data);
         if ($image) {
             $post->setImage('mageplaza/blog/post/image' . $image);
         }
         $tags = $this->getRequest()->getPost('tags', -1);
         if ($tags != -1) {
             $post->setTagsData($this->jsHelper->decodeGridSerializedInput($tags));
         }
         $topics = $this->getRequest()->getPost('topics', -1);
         if ($topics != -1) {
             $post->setTopicsData($this->jsHelper->decodeGridSerializedInput($topics));
         }
         if (!isset($data['categories_ids'])) {
             $post->setCategoriesIds([]);
         }
         $this->_eventManager->dispatch('mageplaza_blog_post_prepare_save', ['post' => $post, 'request' => $this->getRequest()]);
         try {
             $post->save();
             $trafficModel = $this->trafficFactory->create()->load($post->getId(), 'post_id');
             if (!$trafficModel->getId()) {
                 $trafficData = ['post_id' => $post->getId(), 'numbers_view' => '0'];
                 $trafficModel->setData($trafficData);
                 $trafficModel->save();
             }
             $this->messageManager->addSuccess(__('The Post has been saved.'));
             $this->backendSession->setMageplazaBlogPostData(false);
             if ($this->getRequest()->getParam('back')) {
                 $resultRedirect->setPath('mageplaza_blog/*/edit', ['post_id' => $post->getId(), '_current' => true]);
                 return $resultRedirect;
             }
             $resultRedirect->setPath('mageplaza_blog/*/');
             return $resultRedirect;
         } catch (\Magento\Framework\Exception\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 Post.'));
         }
         $this->_getSession()->setMageplazaBlogPostData($data);
         $resultRedirect->setPath('mageplaza_blog/*/edit', ['post_id' => $post->getId(), '_current' => true]);
         return $resultRedirect;
     }
     $resultRedirect->setPath('mageplaza_blog/*/');
     return $resultRedirect;
 }