Created
July 19, 2012 11:52
-
-
Save dfeyer/3143282 to your computer and use it in GitHub Desktop.
Add LOAD_REGISTER to Tx_Fed_ViewHelpers_Page_RenderContentViewHelper
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 | |
/** | |
* ViewHelper used to render content elements in Fluid page templates | |
* | |
* @author Claus Due, Wildside A/S | |
* @author Dominique Feyer <[email protected]> | |
* @package Fed | |
* @subpackage ViewHelpers/Page | |
*/ | |
class Tx_Fed_ViewHelpers_Page_RenderContentViewHelper extends Tx_Fed_Core_ViewHelper_AbstractViewHelper { | |
/** | |
* @var tslib_cObj | |
*/ | |
protected $contentObject; | |
/** | |
* @var Tx_Extbase_Configuration_ConfigurationManagerInterface | |
*/ | |
protected $configurationManager; | |
/** | |
* @param Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager | |
* @return void | |
*/ | |
public function injectConfigurationManager(Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager) { | |
$this->configurationManager = $configurationManager; | |
$this->contentObject = $this->configurationManager->getContentObject(); | |
} | |
/** | |
* Initialize | |
*/ | |
public function initializeArguments() { | |
$this->registerArgument('loadRegister', 'array', 'List of LOAD_REGISTER variable', FALSE, 0); | |
$this->registerArgument('column', 'integer', 'Name of the column to render', FALSE, 0); | |
$this->registerArgument('as', 'string', 'If specified, adds template variable and assumes you manually iterate through {content}'); | |
$this->registerArgument('limit', 'integer', 'Optional limit to the number of content elements to render'); | |
$this->registerArgument('order', 'string', 'Optional sort field of content elements - RAND() supported', FALSE, 'sorting'); | |
$this->registerArgument('sortDirection', 'string', 'Optional sort direction of content elements', FALSE, 'ASC'); | |
$this->registerArgument('pageUid', 'integer', 'If set, gets content from this page'); | |
$this->registerArgument('slide', 'integer', 'Enables Content Sliding - amount of levels which shall get walked up the rootline. For infinite sliding (till the rootpage) set to -1)', FALSE, 0); | |
$this->registerArgument('slideCollect', 'integer', 'Enables collecting of Content Elements - amount of levels which shall get walked up the rootline. For infinite sliding (till the rootpage) set to -1 (lesser value for slide and slide.collect applies))', FALSE, 0); | |
$this->registerArgument('slideCollectReverse', 'boolean', 'Normally when collecting content elements the elements from the actual page get shown on the top and those from the parent pages below those. You can invert this behaviour (actual page elements at bottom) by setting this flag))', FALSE, 0); | |
} | |
/** | |
* Render method | |
* | |
* @return string | |
*/ | |
public function render() { | |
if (TYPO3_MODE == 'BE') { | |
return ''; | |
} | |
$content = $this->getContentRecords(); | |
if ($this->arguments['as']) { | |
$this->templateVariableContainer->add($this->arguments['as'], $content); | |
$html = $this->renderChildren(); | |
$this->templateVariableContainer->remove($this->arguments['as']); | |
} else { | |
$html = ""; | |
foreach ($content as $contentRecord) { | |
$html .= $contentRecord . LF; | |
} | |
} | |
return $html; | |
} | |
/** | |
* Get content records based on column and pid | |
* | |
* @author Claus Due, Wildside A/S | |
* @author Daniel Schöne, schoene.it (added "slide" feature) | |
* @return array | |
*/ | |
protected function getContentRecords() { | |
$loadRegister = FALSE; | |
if (!empty($this->arguments['loadRegister'])) { | |
$this->contentObject->cObjGetSingle('LOAD_REGISTER', $this->arguments['loadRegister']); | |
$loadRegister = TRUE; | |
} | |
$pid = $this->arguments['pageUid'] ? $this->arguments['pageUid'] : $GLOBALS['TSFE']->id; | |
$order = $this->arguments['order'] . ' ' . $this->arguments['sortDirection']; | |
$colPos = $this->arguments['column']; | |
$slide = $this->arguments['slide'] ? $this->arguments['slide'] : FALSE; | |
$slideCollect = $this->arguments['slideCollect'] ? $this->arguments['slideCollect'] : FALSE; | |
if($slideCollect !== FALSE){ | |
$slide = min($slide, $slideCollect); | |
} | |
$slideCollectReverse = $this->arguments['slideCollectReverse']; | |
$rootLine = NULL; | |
if($slide){ | |
$pageSelect = new t3lib_pageSelect(); | |
$rootLine = $pageSelect->getRootLine($pid); | |
if($slideCollectReverse){ | |
$rootLine = array_reverse($rootLine); | |
} | |
} | |
$content = array(); | |
do { | |
if ($slide){ | |
$page = array_shift($rootLine); | |
if (!$page){ | |
break; | |
} | |
$pid = $page['uid']; | |
} | |
$conditions = "pid = '" . $pid ."' AND colPos = '" . $colPos . "' AND tx_flux_column = '' " . $GLOBALS['TSFE']->cObj->enableFields('tt_content') . " AND (sys_language_uid IN (-1,0) OR (sys_language_uid = '" . $GLOBALS['TSFE']->sys_language_uid . "' AND l18n_parent = '0'))"; | |
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'tt_content', $conditions, 'uid', $order, $this->arguments['limit']); | |
while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { | |
$conf = array( | |
'tables' => 'tt_content', | |
'source' => $row['uid'], | |
'dontCheckPid' => 0 | |
); | |
array_push($content, $GLOBALS['TSFE']->cObj->RECORDS($conf)); | |
} | |
$GLOBALS['TYPO3_DB']->sql_free_result($res); | |
if (count($content) && !$slideCollect){ | |
break; | |
} | |
} while($slide !== FALSE && --$slide !== -1); | |
if ($loadRegister) { | |
$this->contentObject->cObjGetSingle('RESTORE_REGISTER', ''); | |
} | |
return $content; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment