Ejemplo n.º 1
0
 /**
  * Validate and Match Blog Post and modify request
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return bool
  */
 public function match(\Magento\Framework\App\RequestInterface $request)
 {
     $url_key = trim($request->getPathInfo(), '/blog/');
     $url_key = rtrim($url_key, '/');
     /** @var \OsmanSorkar\Blog\Model\Post $post */
     $post = $this->_postFactory->create();
     $post_id = $post->checkUrlKey($url_key);
     if (!$post_id) {
         return null;
     }
     $request->setModuleName('blog')->setControllerName('view')->setActionName('index')->setParam('post_id', $post_id);
     $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $url_key);
     return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
 }
Ejemplo n.º 2
0
 /**
  * @return \Ashsmith\Blog\Model\Post
  */
 public function getPost()
 {
     // Check if posts has already been defined
     // makes our block nice and re-usable! We could
     // pass the 'posts' data to this block, with a collection
     // that has been filtered differently!
     if (!$this->hasData('post')) {
         if ($this->getPostId()) {
             /** @var \Ashsmith\Blog\Model\Post $page */
             $post = $this->postFactory->create();
         } else {
             $post = $this->post;
         }
         $this->setData('post', $post);
     }
     $postData = $this->getData('post');
     return $postData->setContent($this->filterProvider->getPageFilter()->filter($postData->getContent()));
 }