/** * Return array of options as value-label pairs * * @return array Format: array(array('value' => '<value>', 'label' => '<label>'), ...) */ public function toOptionArray() { $options[] = ['label' => '', 'value' => '']; $availableOptions = $this->post->getAvailableStatuses(); foreach ($availableOptions as $key => $value) { $options[] = ['label' => $value, 'value' => $key]; } return $options; }
public function testRemoveByUrl() { $this->post->expects($this->exactly(2))->method('checkUrlKey')->willReturn(self::POST_ID); $this->post->expects($this->exactly(2))->method('load')->with(self::POST_ID)->willReturn($this->post); $this->post->expects($this->once())->method('getId')->willReturn(self::POST_ID); $this->postFactory->expects($this->exactly(2))->method('create')->willReturn($this->post); $this->post->expects($this->once())->method('getUrlKey')->willReturn(self::URL); $actual = $this->postRegistry->retrieveByUrl(self::URL); $this->assertSame($this->post, $actual); $this->postRegistry->removeByUrl(self::URL); $actual = $this->postRegistry->retrieveByUrl(self::URL); $this->assertSame($this->post, $actual); }
public function prepareResultPost(Action $action, $id = null) { if ($id !== null && $id !== $this->_post->getId()) { $delimiterPosition = strpos($id, '|'); if ($delimiterPosition) { $id = substr($id, 0, $delimiterPosition); } if (!$this->_post->load($id)) { return false; } } if (!$this->_post->getId()) { return false; } /** @var \Magento\Framework\View\Result\Page $resultPage */ $page = $this->_pageFactory->create(); $page->addHandle('blog_post_view'); $page->addPageLayoutHandles(['id' => $this->_post->getId()]); $this->_eventManager->dispatch('ism_blog_post_render', ['post' => $this->_post, 'controller_action' => $action]); return $page; }
/** * Check thumbnail and create it if need. * * @return bool */ public function checkAndCreate() { if ($this->_mediaDirectory->isFile($this->_cacheDir . $this->_post->getImageUrl())) { return true; } if (!$this->_mediaDirectory->isFile(Upload::UPLOAD_POST_IMAGE_DIR . $this->_post->getImageUrl())) { return false; } $image = $this->_imageFactory->create(array('file' => $this->_mediaDirectory->getAbsolutePath(Upload::UPLOAD_POST_IMAGE_DIR . $this->_post->getImageUrl()))); $image->setWH(75, 75); $image->resize(); $image->save(DirectoryList::PUB . DIRECTORY_SEPARATOR . DirectoryList::MEDIA . DIRECTORY_SEPARATOR . $this->_cacheDir . $this->_post->getImageUrl()); return true; }
public function push(Post $post) { $this->postRegistryById[$post->getId()] = $post; $this->postRegistryByUrl[$post->getUrlKey()] = $post; return $this; }