Skip to content
Snippets Groups Projects
Commit 7deac45a authored by Fabian Galinski's avatar Fabian Galinski :pouting_cat:
Browse files

[TASK] Movement of a Xclass to languagevisibility. Raise version to 3.9.4

parent 1b8a0735
No related branches found
No related tags found
No related merge requests found
<?php
namespace SGalinski\SgNews\Xclass;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.de)
* 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 2 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 TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\Qom;
use TYPO3\Languagevisibility\Service\FrontendServices;
/**
* Xclass for the TYPO3 db backend, which handles, that the l18n_cfg parameters are used for pages in Extbase.
*/
class Typo3DbBackend extends \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbBackend {
/**
* 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 Qom\SourceInterface $source The source (selector od join)
* @param array $rows
* @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
* @param null|int $workspaceUid
* @return array
*/
protected function doLanguageAndWorkspaceOverlay(Qom\SourceInterface $source, array $rows, \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings, $workspaceUid = null)
{
if ($source instanceof Qom\SelectorInterface) {
$tableName = $source->getSelectorName();
} elseif ($source instanceof Qom\JoinInterface) {
$tableName = $source->getRight()->getSelectorName();
} else {
// No proper source, so we do not have a table name here
// we cannot do an overlay and return the original rows instead.
return $rows;
}
$pageRepository = $this->getPageRepository();
if (is_object($GLOBALS['TSFE'])) {
if ($workspaceUid !== null) {
$pageRepository->versioningWorkspaceId = $workspaceUid;
}
} else {
if ($workspaceUid === null) {
$workspaceUid = $GLOBALS['BE_USER']->workspace;
}
$pageRepository->versioningWorkspaceId = $workspaceUid;
}
// Fetches the move-placeholder in case it is supported
// by the table and if there's only one row in the result set
// (applying this to all rows does not work, since the sorting
// order would be destroyed and possible limits not met anymore)
if (!empty($pageRepository->versioningWorkspaceId)
&& BackendUtility::isTableWorkspaceEnabled($tableName)
&& count($rows) === 1
) {
$movePlaceholder = $this->databaseHandle->exec_SELECTgetSingleRow(
$tableName . '.*',
$tableName,
't3ver_state=3 AND t3ver_wsid=' . $pageRepository->versioningWorkspaceId
. ' AND t3ver_move_id=' . $rows[0]['uid']
);
if (!empty($movePlaceholder)) {
$rows = array($movePlaceholder);
}
}
$isLanguagevisibilityLoaded = ExtensionManagementUtility::isLoaded('languagevisibility');
$overlaidRows = array();
foreach ($rows as $row) {
// If current row is a translation select its parent
if (isset($tableName) && isset($GLOBALS['TCA'][$tableName])
&& isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])
&& isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'])
&& !isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerTable'])
) {
if (isset($row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']])
&& $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0
) {
$row = $this->databaseHandle->exec_SELECTgetSingleRow(
$tableName . '.*',
$tableName,
$tableName . '.uid=' . (int)$row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] .
' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0'
);
}
}
$pageRepository->versionOL($tableName, $row, true);
if ($tableName == 'pages') {
// Start of the patch
// Applies the language visibility logic.
if ($isLanguagevisibilityLoaded && is_object($GLOBALS['TSFE'])) {
$sysLanguageUid = $GLOBALS['TSFE']->sys_language_uid;
if (!FrontendServices::checkVisiblityForElement((int) $row['uid'], $tableName, $sysLanguageUid)) {
// Page not visible
continue;
}
}
// End of the patch
$row = $pageRepository->getPageOverlay($row, $querySettings->getLanguageUid());
if ($row === null || !is_array($row)) {
continue;
}
// Start of the patch
$l18nConfiguration = $row['l18n_cfg'];
if ($l18nConfiguration > 0) {
if (is_object($GLOBALS['TSFE'])) {
$sysLanguageUid = $GLOBALS['TSFE']->sys_language_uid;
if ($sysLanguageUid > 0) {
// Request the overlay record for the sys_language_uid:
$pageOverlay = $pageRepository->getPageOverlay($row['uid'], $sysLanguageUid);
if (empty($pageOverlay) &&
\TYPO3\CMS\Core\Utility\GeneralUtility::hideIfNotTranslated($l18nConfiguration)
) {
// Page is not available in default language.
continue;
}
}
if (!$sysLanguageUid &&
\TYPO3\CMS\Core\Utility\GeneralUtility::hideIfDefaultLanguage($l18nConfiguration)
) {
// Page is not available in default language.
continue;
}
}
}
// End of the patch
} elseif (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])
&& $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== ''
&& !isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerTable'])
) {
if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1, 0))) {
$overlayMode = $querySettings->getLanguageOverlayMode();
if ($overlayMode !== 'hideNonTranslated' || preg_match('/sys_file_.*/is', $tableName)) {
$overlayMode = $querySettings->getLanguageMode() === 'strict' ? 'hideNonTranslated' : '';
}
$row = $pageRepository->getRecordOverlay($tableName, $row, $querySettings->getLanguageUid(), $overlayMode);
}
}
if ($row !== null && is_array($row)) {
$overlaidRows[] = $row;
}
}
return $overlaidRows;
}
}
?>
......@@ -6,7 +6,7 @@
"license": [
"GPL-2.0+"
],
"version": "3.9.3",
"version": "3.9.4",
"support": {
},
"repositories": [
......@@ -19,6 +19,7 @@
"typo3/cms-core": "7.6.0 - 8.7.99"
},
"suggest": {
"sgalinski/languagevisibility": "Minimum version 1.1 required, if multi language is enabled",
"sgalinski/sg-ajax": "Needed for the like feature",
"sgalinski/sg-comments": "Flexible comments system",
"typo3-ter/rx-shariff": "Social Share possibilities"
......
......@@ -19,7 +19,7 @@ $EM_CONF[$_EXTKEY] = [
'modify_tables' => '',
'clearCacheOnLoad' => 0,
'lockType' => '',
'version' => '3.9.3',
'version' => '3.9.4',
'constraints' => [
'depends' => [
'typo3' => '7.6.0-8.7.99',
......@@ -30,6 +30,7 @@ $EM_CONF[$_EXTKEY] = [
'sg_comments' => '2.1.0-',
'rx_shariff' => '5.0.1-',
'sg_ajax' => '1.0.6-',
'languagevisibility' => '1.1.0-',
],
],
'suggests' => [],
......
......@@ -77,8 +77,6 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['proc
// Xclasses
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['TYPO3\CMS\Core\Page\PageRenderer'] =
['className' => 'SGalinski\SgNews\Xclass\PageRenderer'];
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbBackend'] =
['className' => 'SGalinski\SgNews\Xclass\Typo3DbBackend'];
// add realurl configuration
if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('realurl')) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment