protected function getPreviousLocalizedRecordUid($uid, $language, DataHandler $reference)
{
$table = 'tt_content';
$previousLocalizedRecordUid = $uid;
$sortRow = $GLOBALS['TCA'][$table]['ctrl']['sortby'];
$select = $sortRow . ',pid,uid,colPos,tx_flux_parent,tx_flux_column';
// Get the sort value of the default language record
$row = BackendUtility::getRecord($table, $uid, $select);
if (is_array($row)) {
// Find the previous record in default language on the same page
$where = sprintf('pid=%d AND sys_language_uid=0 AND %s < %d', (int) $row['pid'], $sortRow, (int) $row[$sortRow]);
// Respect the colPos for content elements
if ($table === 'tt_content') {
$where .= sprintf(' AND colPos=%d AND tx_flux_column=\'%s\' AND tx_flux_parent=%d', (int) $row['colPos'], $row['tx_flux_column'], (int) $row['tx_flux_parent']);
}
$where .= $reference->deleteClause($table);
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select, $table, $where, '', $sortRow . ' DESC', '1');
// If there is an element, find its localized record in specified localization language
if ($previousRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$previousLocalizedRecord = BackendUtility::getRecordLocalization($table, $previousRow['uid'], $language);
if (is_array($previousLocalizedRecord[0])) {
$previousLocalizedRecordUid = $previousLocalizedRecord[0]['uid'];
}
}
$GLOBALS['TYPO3_DB']->sql_free_result($res);
}
return $previousLocalizedRecordUid;
}