Last active
August 29, 2015 14:24
-
-
Save htuscher/f88027a15a4e2651cf16 to your computer and use it in GitHub Desktop.
Neos create node links in Flow plugin
This file contains hidden or 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
| <?php | |
| namespace Jhoechtl\MySite\Controller; | |
| /* * | |
| * This script belongs to the TYPO3 Flow package "Jhoechtl.MySite". * | |
| * * | |
| * */ | |
| use TYPO3\Flow\Annotations as Flow; | |
| use TYPO3\Flow\Mvc\Controller\ActionController; | |
| use TYPO3\Neos\Service\LinkingService; | |
| class PageViewController extends ActionController { | |
| /** | |
| * @Flow\Inject | |
| * @var \Jhoechtl\MySite\Domain\Repository\PageViewRepository | |
| */ | |
| protected $pageViewRepository; | |
| /** | |
| * @Flow\Inject | |
| * @var LinkingService | |
| */ | |
| protected $linkingService; | |
| /** | |
| * @return void | |
| */ | |
| public function viewsAction() { | |
| $days = $this->request->getInternalArgument('__days'); | |
| $numberOfItems = $this->request->getInternalArgument('__numberOfItems'); | |
| $documentNode = $this->request->getInternalArgument('__documentNode'); | |
| $news = (array)$this->pageViewRepository->mostViewedByDays($days, $numberOfItems); | |
| $news = array_map(function($newsEntry) use ($documentNode) { | |
| /** @var \TYPO3\TYPO3CR\Domain\Model\NodeData $node */ | |
| $node = $newsEntry['node']; | |
| $newsEntry['uri'] = $this->linkingService->createNodeUri( | |
| $this->getControllerContext(), | |
| $node->getPath(), | |
| $documentNode | |
| ); | |
| return $newsEntry; | |
| }, $news); | |
| $this->view->assign('days', $days); | |
| $this->view->assign('numberOfItems', $numberOfItems); | |
| $this->view->assign('newsList', $news); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment