-
-
Save wikipeter/10395334 to your computer and use it in GitHub Desktop.
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
{namespace vm=Vm\Vmtemplates\ViewHelpers} | |
<div class="navigation"> | |
<vm:link.next newsItem="{newsItem}" settings="{settings}" class="news-next"> | |
<span></span> | |
</vm:link.next> | |
<vm:link.prev newsItem="{newsItem}" settings="{settings}" class="news-prev"> | |
<span></span> | |
</vm:link.prev> | |
</div> |
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
<?php | |
namespace Vm\Vmtemplates\ViewHelpers; | |
/***************************************************************** | |
* Copyright notice | |
* | |
* (c) 2014 Benjamin Rau <rau@codearts.at> | |
* | |
* All rights reserved | |
* | |
* This script is part of the TYPO3 project. The TYPO3 project is | |
* free software; you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation; either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* The GNU General Public License can be found at | |
* http://www.gnu.org/copyleft/gpl.html. | |
* | |
* This script is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* This copyright notice MUST APPEAR in all copies of the script! | |
*****************************************************************/ | |
/** | |
* ViewHelper to render links for prev news | |
*/ | |
class LinkViewHelper extends \Tx_News_ViewHelpers_LinkViewHelper { | |
/** | |
* @var \Tx_News_Domain_Repository_NewsRepository | |
*/ | |
protected $newsRepository; | |
/** | |
* @var \Tx_News_Domain_Repository_NewsRepository $newsRepository | |
* @return void | |
*/ | |
public function injectNewsRepository(\Tx_News_Domain_Repository_NewsRepository $newsRepository) { | |
$this->newsRepository = $newsRepository; | |
} | |
/** | |
* Render link to news item or internal/external pages | |
* | |
* @param \Tx_News_Domain_Model_News $newsItem current news object | |
* @param array $settings | |
* @param boolean $uriOnly return only the url without the a-tag | |
* @param array $configuration optional typolink configuration | |
* @return string link | |
*/ | |
public function render(\Tx_News_Domain_Model_News $newsItem, array $settings = array(), $uriOnly = FALSE, $configuration = array()) { | |
$objectManager = \t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager'); | |
/** @var \Tx_Extbase_Persistence_Typo3QuerySettings $defaultQuerySettings */ | |
$defaultQuerySettings = $objectManager->get('Tx_Extbase_Persistence_Typo3QuerySettings'); | |
$defaultQuerySettings->setStoragePageIds(array($newsItem->getPid())); | |
$this->newsRepository->setDefaultQuerySettings($defaultQuerySettings); | |
$query = $this->newsRepository->createQuery(); | |
$newsItems = $query->execute()->toArray(); | |
$newsItemIndex = array_search($newsItem, $newsItems, TRUE); | |
if (0 === (integer) array_search($newsItem, $newsItems, TRUE)) { | |
return NULL; | |
} | |
$newsItem = $newsItems[$newsItemIndex-1]; | |
return parent::render($newsItem, $settings, $uriOnly, $configuration); | |
} | |
} |
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
<?php | |
namespace Vm\Vmtemplates\ViewHelpers\Link; | |
/***************************************************************** | |
* Copyright notice | |
* | |
* (c) 2014 Benjamin Rau <rau@codearts.at> | |
* | |
* All rights reserved | |
* | |
* This script is part of the TYPO3 project. The TYPO3 project is | |
* free software; you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation; either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* The GNU General Public License can be found at | |
* http://www.gnu.org/copyleft/gpl.html. | |
* | |
* This script is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* This copyright notice MUST APPEAR in all copies of the script! | |
*****************************************************************/ | |
use Vm\Vmtemplates\ViewHelpers\LinkViewHelper; | |
/** | |
* ViewHelper to render links for prev news | |
*/ | |
class NextViewHelper extends LinkViewHelper { | |
/** | |
* @var \Tx_News_Domain_Repository_NewsRepository $newsRepository | |
* @return void | |
*/ | |
public function injectNewsRepository(\Tx_News_Domain_Repository_NewsRepository $newsRepository) { | |
$this->newsRepository = $newsRepository; | |
$this->newsRepository->setDefaultOrderings( | |
array('datetime' => \Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING), | |
array('tstamp' => \Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING) | |
); | |
} | |
} |
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
<?php | |
namespace Vm\Vmtemplates\ViewHelpers\Link; | |
/***************************************************************** | |
* Copyright notice | |
* | |
* (c) 2014 Benjamin Rau <rau@codearts.at> | |
* | |
* All rights reserved | |
* | |
* This script is part of the TYPO3 project. The TYPO3 project is | |
* free software; you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation; either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* The GNU General Public License can be found at | |
* http://www.gnu.org/copyleft/gpl.html. | |
* | |
* This script is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* This copyright notice MUST APPEAR in all copies of the script! | |
*****************************************************************/ | |
use Vm\Vmtemplates\ViewHelpers\LinkViewHelper; | |
/** | |
* ViewHelper to render links for prev news | |
*/ | |
class PrevViewHelper extends LinkViewHelper { | |
/** | |
* @var \Tx_News_Domain_Repository_NewsRepository $newsRepository | |
* @return void | |
*/ | |
public function injectNewsRepository(\Tx_News_Domain_Repository_NewsRepository $newsRepository) { | |
$this->newsRepository = $newsRepository; | |
$this->newsRepository->setDefaultOrderings( | |
array('datetime' => \Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING), | |
array('tstamp' => \Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment