/** * Performs workspace and language overlay on the given row array. The language and workspace id is automatically * detected (depending on FE or BE context). You can also explicitly set the language/workspace id. * * @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source (selector od join) * @param array $row The row array (as reference) * @param string $languageUid The language id * @param string $workspaceUidUid The workspace id * @return void */ protected function doLanguageAndWorkspaceOverlay(Tx_Extbase_Persistence_QOM_SourceInterface $source, array $rows, $languageUid = NULL, $workspaceUid = NULL) { $overlayedRows = array(); foreach ($rows as $row) { if (!$this->pageSelectObject instanceof t3lib_pageSelect) { if (TYPO3_MODE == 'FE') { if (is_object($GLOBALS['TSFE'])) { $this->pageSelectObject = $GLOBALS['TSFE']->sys_page; } else { require_once PATH_t3lib . 'class.t3lib_page.php'; $this->pageSelectObject = t3lib_div::makeInstance('t3lib_pageSelect'); } } else { require_once PATH_t3lib . 'class.t3lib_page.php'; $this->pageSelectObject = t3lib_div::makeInstance('t3lib_pageSelect'); } } if (is_object($GLOBALS['TSFE'])) { if ($languageUid === NULL) { $languageUid = $GLOBALS['TSFE']->sys_language_uid; $languageMode = $GLOBALS['TSFE']->sys_language_mode; } if ($workspaceUid !== NULL) { $this->pageSelectObject->versioningWorkspaceId = $workspaceUid; } } else { if ($languageUid === NULL) { $languageUid = intval(t3lib_div::_GP('L')); } if ($workspaceUid === NULL) { $workspaceUid = $GLOBALS['BE_USER']->workspace; } $this->pageSelectObject->versioningWorkspaceId = $workspaceUid; } if ($source instanceof Tx_Extbase_Persistence_QOM_SelectorInterface) { $tableName = $source->getSelectorName(); } elseif ($source instanceof Tx_Extbase_Persistence_QOM_JoinInterface) { $tableName = $source->getLeft()->getSelectorName(); } $this->pageSelectObject->versionOL($tableName, $row, TRUE); if (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== '') { if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1, 0))) { $overlayMode = $languageMode === 'strict' ? 'hideNonTranslated' : ''; $row = $this->pageSelectObject->getRecordOverlay($tableName, $row, $languageUid, $overlayMode); } } if ($row !== NULL) { $overlayedRows[] = $row; } } return $overlayedRows; }
/** * Creates language-overlay for records in general (where translation is found in records from the same table) * * @param string Table name * @param array Record to overlay. Must containt uid, pid and $table]['ctrl']['languageField'] * @param integer Pointer to the sys_language uid for content on the site. * @param string Overlay mode. If "hideNonTranslated" then records without translation will not be returned un-translated but unset (and return value is false) * @return mixed Returns the input record, possibly overlaid with a translation. But if $OLmode is "hideNonTranslated" then it will return false if no translation is found. */ function getRecordOverlay($table, $row, $sys_language_content, $OLmode = '') { //echo $table.'--'.$row['uid'].'--'.$sys_language_content.'--'.$OLmode; //echo '<hr>'; //return parent::getRecordOverlay($table,$row,$sys_language_content,$OLmode); global $TCA; //echo $row['uid'].'-'; //39348 //unset olmode $OLmode = ''; // die('���'); //call service to know if element is visible and which overlay language to use try { $element = tx_languagevisibility_feservices::getElement($row['uid'], $table); $overlayLanguage = tx_languagevisibility_feservices::getOverlayLanguageIdForElement($element, $sys_language_content); } catch (Exception $e) { //for any other tables: return parent::getRecordOverlay($table, $row, $sys_language_content, $OLmode); } //debug($overlayLanguage); if ($overlayLanguage === false) { //echo 'unset '.$table.' / '.$row['uid']; //not visible: unset($row); return $row; } else { //visible: if ($overlayLanguage != 0) { if ($element instanceof tx_languagevisibility_fceelement) { //for FCE the overlay processing is handled by templavoila module, so mark the row with additional infos: $languageRep = t3lib_div::makeInstance('tx_languagevisibility_languagerepository'); $overlayLanguageObj = $languageRep->getLanguageById($overlayLanguage); $row['_OVERLAYLANGUAGEISOCODE'] = $overlayLanguageObj->getIsoCode(); return $row; } elseif ($element instanceof tx_languagevisibility_fceoverlayelement) { //now its getting tricky: we need to return overlay record with merged XML $olrow = $this->_getDatabaseTranslationOverlayRecord('tt_content', $row, $overlayLanguage); if ($GLOBALS['TSFE']) { $GLOBALS['TSFE']->includeTCA('tt_content'); } //parse fce xml, and where a xml field is empty in olrow -> use default one $flexObj = t3lib_div::makeInstance('t3lib_flexformtools'); $this->_callbackVar_defaultXML = t3lib_div::xml2array($row['tx_templavoila_flex']); $this->_callbackVar_overlayXML = t3lib_div::xml2array($olrow['tx_templavoila_flex']); if (!is_array($this->_callbackVar_overlayXML)) { $this->_callbackVar_overlayXML = array(); } $return = $flexObj->traverseFlexFormXMLData('tt_content', 'tx_templavoila_flex', $row, $this, '_callback_checkXMLFieldsForFallback'); $row = parent::getRecordOverlay($table, $row, $overlayLanguage, $OLmode); $row['tx_templavoila_flex'] = t3lib_div::array2xml($this->_callbackVar_overlayXML); return $row; } else { //for default elements just do TYPO3 default overlay return parent::getRecordOverlay($table, $row, $overlayLanguage, $OLmode); } } else { return $row; } } }
/** * * @param unknown_type $table * @param unknown_type $row * @param unknown_type $sys_language_content * @param unknown_type $OLmode * @param t3lib_pageSelect $parent * @return void */ public function getRecordOverlay_postProcess($table, &$row, &$sys_language_content, $OLmode, t3lib_pageSelect $parent) { if (!is_array($row) || !isset($row['uid']) || $sys_language_content == 0) { return; } try { $element = tx_languagevisibility_feservices::getElement($row['uid'], $table); $overlayLanguage = tx_languagevisibility_feservices::getOverlayLanguageIdForElement($element, $sys_language_content); } catch (Exception $e) { return; } if ($element instanceof tx_languagevisibility_fceelement) { //for FCE the overlay processing is handled by templavoila module, so mark the row with additional infos: $languageRep = t3lib_div::makeInstance('tx_languagevisibility_languagerepository'); $overlayLanguageObj = $languageRep->getLanguageById($overlayLanguage); $row['_OVERLAYLANGUAGEISOCODE'] = $overlayLanguageObj->getIsoCode(); } elseif ($element instanceof tx_languagevisibility_fceoverlayelement) { //now its getting tricky: we need to return overlay record with merged XML $row['tx_templavoila_flex'] = $row['_ORIG_tx_templavoila_flex']; unset($row['_ORIG_tx_templavoila_flex']); $olrow = $this->_getDatabaseTranslationOverlayRecord('tt_content', $row, $overlayLanguage); if ($GLOBALS['TSFE']) { $GLOBALS['TSFE']->includeTCA('tt_content'); } //parse fce xml, and where a xml field is empty in olrow -> use default one $flexObj = t3lib_div::makeInstance('t3lib_flexformtools'); $this->_callbackVar_defaultXML = t3lib_div::xml2array($row['tx_templavoila_flex']); $this->_callbackVar_overlayXML = t3lib_div::xml2array($olrow['tx_templavoila_flex']); if (!is_array($this->_callbackVar_overlayXML)) { $this->_callbackVar_overlayXML = array(); } $return = $flexObj->traverseFlexFormXMLData('tt_content', 'tx_templavoila_flex', $row, $this, '_callback_checkXMLFieldsForFallback'); if ($sys_language_content != $overlayLanguage) { $row = $parent->getRecordOverlay($table, $row, $overlayLanguage, $OLmode); } $row['tx_templavoila_flex'] = t3lib_div::array2xml($this->_callbackVar_overlayXML); } }