Skip to content

Commit

Permalink
[TASK] Refactor reading of pid in AbstractContentViewHelper
Browse files Browse the repository at this point in the history
Method has been created to make a uniform way of getting the currently configured or auto-detected PID value to use when reading content records.
  • Loading branch information
NamelessCoder committed Aug 4, 2014
1 parent ad6d5bb commit bffc104
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions Classes/ViewHelpers/Content/AbstractContentViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,7 @@ protected function getContentRecords($limit = NULL, $order = NULL) {
$loadRegister = TRUE;
}

$pageUid = $GLOBALS['TSFE']->id;
if (FALSE === empty($this->arguments['pageUid'])) {
$pageUid = $this->arguments['pageUid'];
} elseif (FALSE === empty($GLOBALS['TSFE']->page['content_from_pid'])) {
$pageUid = $GLOBALS['TSFE']->page['content_from_pid'];
}
$pageUid = intval($pageUid);

$pageUid = $this->getPageUid();
if (FALSE === empty($order)) {
$sortDirection = strtoupper(trim($this->arguments['sortDirection']));
if ('ASC' !== $sortDirection && 'DESC' !== $sortDirection) {
Expand Down Expand Up @@ -182,6 +175,24 @@ protected function getContentRecords($limit = NULL, $order = NULL) {
return $content;
}

/**
* Gets the configured, or the current page UID if
* none is configured in arguments and no content_from_pid
* value exists in the current page record's attributes.
*
* @return integer
*/
protected function getPageUid() {
$pageUid = (integer) $this->arguments['pageUid'];
if (1 > $pageUid) {
$pageUid = (integer) $GLOBALS['TSFE']->page['content_from_pid'];
}
if (1 > $pageUid) {
$pageUid = (integer) $GLOBALS['TSFE']->id;
}
return $pageUid;
}

/**
* This function renders an array of tt_content record into an array of rendered content
* it returns a list of elements rendered by typoscript RECORD function
Expand Down

0 comments on commit bffc104

Please sign in to comment.