/** * Return a blog post from given post id. * * @param Action $action * @param null $postId * @return \Magento\Framework\View\Result\Page|bool */ public function prepareResultPost(Action $action, $postId = null) { if ($postId !== null && $postId !== $this->_post->getId()) { $delimiterPosition = strrpos($postId, '|'); if ($delimiterPosition) { $postId = substr($postId, 0, $delimiterPosition); } if (!$this->_post->load($postId)) { return false; } } if (!$this->_post->getId()) { return false; } /** @var \Magento\Framework\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); // We can add our own custom page handles for layout easily. $resultPage->addHandle('blog_post_view'); // This will generate a layout handle like: blog_post_view_id_1 // giving us a unique handle to target specific blog posts if we wish to. $resultPage->addPageLayoutHandles(['id' => $this->_post->getId()]); // Magento is event driven after all, lets remember to dispatch our own, to help people // who might want to add additional functionality, or filter the posts somehow! $this->_eventManager->dispatch('balance_blog_post_render', ['post' => $this->_post, 'controller_action' => $action]); return $resultPage; }
/** * Get options * * @return array */ public function toOptionArray() { $options[] = ['label' => '', 'value' => '']; $availableOptions = $this->post->getAvailableStatuses(); foreach ($availableOptions as $key => $value) { $options[] = ['label' => $value, 'value' => $key]; } return $options; }