Returns valid items (that are to be displayed), for a given block.
public getValidBlockItems ( |
||
$block | ||
리턴 |
public function injectValidItems(FilterViewParametersEvent $event) { $view = $event->getView(); if ($view instanceof BlockView) { $event->getParameterBag()->set('valid_items', $this->pageService->getValidBlockItems($view->getBlock())); } }
/** * Render the block * * @param \eZ\Publish\Core\FieldType\Page\Parts\Block $block * @param array $params * @param array $cacheSettings settings for the HTTP cache, 'smax-age' and * 'max-age' are checked. * * @return \Symfony\Component\HttpFoundation\Response */ public function viewBlock(Block $block, array $params = array(), array $cacheSettings = array()) { $response = new Response(); if ($this->getParameter('content.view_cache') === true) { $response->setPublic(); if (isset($cacheSettings['smax-age']) && is_int($cacheSettings['smax-age'])) { $response->setSharedMaxAge((int) $cacheSettings['smax-age']); } if (isset($cacheSettings['max-age']) && is_int($cacheSettings['max-age'])) { $response->setMaxAge((int) $cacheSettings['max-age']); } } $response->setContent($this->viewManager->renderBlock($block, $params + array('pageService' => $this->pageService, 'valid_items' => $this->pageService->getValidBlockItems($block)))); return $response; }
/** * @covers eZ\Publish\Core\FieldType\Page\PageService::hasStorageGateway * @covers eZ\Publish\Core\FieldType\Page\PageService::getStorageGateway * @covers eZ\Publish\Core\FieldType\Page\PageService::getValidBlockItems */ public function testGetValidBlockItems() { $block = $this->buildBlock(); $items = array(new Item(), new Item()); $this->storageGateway->expects($this->once())->method('getValidBlockItems')->with($block)->will($this->returnValue($items)); $this->pageService->setStorageGateway($this->storageGateway); // Calling assertion twice to test cache (comes along with storage gateway's getValidBlockItems() that should be called only once. See above) $this->assertSame($items, $this->pageService->getValidBlockItems($block)); $this->assertSame($items, $this->pageService->getValidBlockItems($block)); }