eZ\Publish\Core\FieldType\Page\PageService::getLastValidBlockItem PHP Method

getLastValidBlockItem() public method

Returns the last valid item, for a given block.
public getLastValidBlockItem ( Block $block ) : Item | null
$block eZ\Publish\Core\FieldType\Page\Parts\Block
return eZ\Publish\Core\FieldType\Page\Parts\Item | null
    public function getLastValidBlockItem(Block $block)
    {
        if (isset($this->lastValidItems[$block])) {
            return $this->lastValidItems[$block];
        }
        return $this->lastValidItems[$block] = $this->getStorageGateway()->getLastValidBlockItem($block);
    }

Usage Example

コード例 #1
0
 /**
  * @covers eZ\Publish\Core\FieldType\Page\PageService::hasStorageGateway
  * @covers eZ\Publish\Core\FieldType\Page\PageService::getStorageGateway
  * @covers eZ\Publish\Core\FieldType\Page\PageService::getLastValidBlockItem
  */
 public function testGetLastValidBlockItem()
 {
     $block = $this->buildBlock();
     $lastValidItem = new Item();
     $this->storageGateway->expects($this->once())->method('getLastValidBlockItem')->with($block)->will($this->returnValue($lastValidItem));
     $this->pageService->setStorageGateway($this->storageGateway);
     // Calling assertion twice to test cache (comes along with storage gateway's getLastValidBlockItem() that should be called only once. See above)
     $this->assertSame($lastValidItem, $this->pageService->getLastValidBlockItem($block));
     $this->assertSame($lastValidItem, $this->pageService->getLastValidBlockItem($block));
 }