Created
May 28, 2014 12:02
-
-
Save dfritschy/4b511c033480df27a870 to your computer and use it in GitHub Desktop.
A sample frontpage controller which picks a random banner image from a list of related objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function indexAction( $locationId = 2 ) | |
{ | |
$response = new Response; | |
$response = $this->cacheResponse( $response, $locationId, 10 ); | |
/** @var $repository \eZ\Publish\API\Repository\Repository */ | |
$repository = $this->getRepository(); | |
$contentService = $repository->getContentService(); | |
$locationService = $repository->getLocationService(); | |
$location = $locationService->loadLocation( $locationId ); | |
$content = $contentService->loadContent( $location->contentId ); | |
// get relations of the current version | |
$versionInfo = $contentService->loadVersionInfo( $content->contentInfo ); | |
$relations = $contentService->loadRelations( $versionInfo ); | |
$related = null; | |
/** @var $random \eZ\Publish\API\Repository\Values\Content\Relation */ | |
if ( count( $relations ) ) | |
{ | |
$random = $relations[array_rand( $relations )]; | |
$related = $contentService->loadContent( $random->destinationContentInfo->id ); | |
} | |
return $this->render( | |
"WebmanufakturSiteFrbBundle:full:frb_folder_section.html.twig", | |
array( | |
'content' => $content, | |
'related' => $related | |
), | |
$response | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment