Skip to content

Instantly share code, notes, and snippets.

@pspanja
Created June 16, 2014 14:35
Show Gist options
  • Save pspanja/a0b742a5e78aa75739f6 to your computer and use it in GitHub Desktop.
Save pspanja/a0b742a5e78aa75739f6 to your computer and use it in GitHub Desktop.
<?php
class PageController extends Controller
{
...
/**
*
*
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
*
* @param mixed $id
* @param array $params
* @param array $cacheSettings
*
* @return Response
*/
public function viewBlockById( $id, array $params = array(), array $cacheSettings = array() )
{
$locationId = $this->pageService->getLocationIdByBlockId( $id );
$location = $this->getRepository()->getLocationService()->loadLocation( $locationId );
$content = $this->getRepository()->getContentService()->loadContent( $location->contentId );
foreach ( $content->fields as $field )
{
if ( $field instanceof Value )
{
foreach ( $field->page->zones as $zone )
{
foreach ( $zone->blocks as $block )
{
if ( $block->id === $id )
{
return $this->viewBlock(
$block,
$params,
$cacheSettings
);
}
}
}
}
}
throw new NotFoundException( "Block", $id );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment