...
 
Commits (2)
......@@ -39,8 +39,8 @@ use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
class TcaHook implements TableConfigurationPostProcessingHookInterface {
/**
* //todo: remove hook? probably not needed anymore, since the visbility settings aren't in the table and therefore aren't bound to types anymore
* Alter all types of the pages and tt_content table to include the languagevisibility field
* Still needed with new version, since the languagevisibility field should still be displayed in all pages/tt_content types
*/
public function processData(): void {
foreach ($GLOBALS['TCA']['pages']['types'] as $typeNumber => $value) {
......
......@@ -40,7 +40,7 @@ use TYPO3\Languagevisibility\Service\VisibilityService;
use TYPO3\CMS\Frontend\Page\PageRepository;
/**
* Class tx_languagevisibility_visibility_flag_hooks_t3lib_tcemain
* Class TceMainHook
*/
class TceMainHook {
/**
......@@ -91,9 +91,9 @@ class TceMainHook {
protected function copyLanguageVisibilityFlagsFromParentPage($pageId) {
$page = BackendUtility::getRecord('pages', $pageId);
if (!$page || count(
$page
) <= 0 || (isset($page[$GLOBALS['TCA']['pages']['ctrl']['languageField']]) && $page[$GLOBALS['TCA']['pages']['ctrl']['languageField']] > 0)) {
if (!$page
|| count($page) <= 0
|| (isset($page[$GLOBALS['TCA']['pages']['ctrl']['languageField']]) && $page[$GLOBALS['TCA']['pages']['ctrl']['languageField']] > 0)) {
return;
}
......@@ -104,9 +104,6 @@ class TceMainHook {
$parentUid = $parentPage['uid'];
//$elementfactory = GeneralUtility::makeInstance(ElementFactory::class);
//$element = $elementfactory->getElementForTable('pages', ['uid' => $pageId]);
$languageRep = GeneralUtility::makeInstance(LanguageRepository::class);
$visibilityFlagRepository = GeneralUtility::makeInstance(VisibilityFlagRepository::class);
$pageRepository = GeneralUtility::makeInstance(PageRepository::class);
......@@ -163,8 +160,6 @@ class TceMainHook {
}
if ($recordUid > 0) {
$queryBuilder = [];
unset($queryBuilder);
// since the data mapper automatically copies the flag records,
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(
......@@ -199,12 +194,10 @@ class TceMainHook {
* @param integer $res (but only 0 and 1 is relevant so it's boolean technically)
* @param $tcemain
* @return integer
* @throws \Exception
* @internal param object $this
*/
public
function checkRecordUpdateAccess(
$table, $id, $data, $res, $tcemain
) {
public function checkRecordUpdateAccess($table, $id, $data, $res, $tcemain) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
$queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
$row = $queryBuilder->select('*')
......@@ -223,6 +216,7 @@ class TceMainHook {
} elseif (!BackendServices::hasUserAccessToEditRecord($table, $row)) {
$result = 0;
} else {
$result = $res;
}
return $result;
......@@ -238,8 +232,7 @@ class TceMainHook {
* @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
*/
public
function processDatamap_preProcessFieldArray(
public function processDatamap_preProcessFieldArray(
&$incomingFieldArray, $table, $id, DataHandler $dataHandler
) {
$data = $incomingFieldArray;
......@@ -254,25 +247,8 @@ class TceMainHook {
if (in_array($recordTable, VisibilityService::getSupportedTables(), TRUE)) {
/**
* todo: change info??
* NOTE: This code does not affect new records because the field 'tx_languagevisibility_visibility_flag' is not set
*/
$isPage = $recordTable === 'pages';
//todo: check what this was for and change or remove
/**if ($isPage) {
* $incomingFieldArray['tx_languagevisibility_visibility_flag_inheritanceflag_original'] = in_array(
* 'no+', $incomingFieldArray['tx_languagevisibility_visibility_flag'], TRUE
* ) ? '1' : '0';
*
* // todo: remove pages_language_overlay branch?
* } elseif ($table === 'pages_language_overlay') {
* $incomingFieldArray['tx_languagevisibility_visibility_flag_inheritanceflag_overlayed'] = in_array(
* 'no+', $incomingFieldArray['tx_languagevisibility_visibility_flag'], TRUE
* ) ? '1' : '0';
* }**/
$enableLogging = FALSE;
if (isset($incomingFieldArray['enableLogging'])) {
$enableLogging = (boolean) $incomingFieldArray['enableLogging'];
......@@ -313,8 +289,8 @@ class TceMainHook {
// flush all caches
CacheManager::getInstance()->flushAllCaches();
// GeneralUtility::makeInstance(VisibilityFlagRepository::class)
// ->deleteDefaultFlags();
GeneralUtility::makeInstance(VisibilityFlagRepository::class)
->deleteDefaultFlags();
// Flush TYPO3 Caching Framework caches
GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)
......@@ -335,8 +311,7 @@ class TceMainHook {
* @return void
* @throws \InvalidArgumentException
*/
protected
function applyVisibilityFlagRecursive(
protected function applyVisibilityFlagRecursive(
int $pageId, int $languageId, string $visibilityFlag, bool $enableLogging, DataHandler $dataHandler
) {
......@@ -448,6 +423,56 @@ class TceMainHook {
}
}
/**
* This method is used to initialize new Elements with the default
*
* @param string $status
* @param string $table
* @param string $id
* @param array $fieldArray
* @param DataHandler $reference
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
*/
public function processDatamap_afterDatabaseOperations(
$status, $table, $id, $fieldArray, &$reference
) {
if (in_array($table, VisibilityService::getSupportedTables(), TRUE)) {
if ($status === 'new') {
$row = [];
if (is_numeric($id) && $id > 0) {
$row['uid'] = $id;
} else {
$row['uid'] = $reference->substNEWwithIDs[$id];
}
/**
* copy the visibility flags of the parent pages
*/
if ($table === 'pages') {
$this->copyLanguageVisibilityFlagsFromParentPage((int) $row['uid']);
return;
}
}
CacheManager::getInstance()->flushAllCaches();
// Flush TYPO3 Caching Framework caches
GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)
->getCache('tx_languagevisibility')
->flush();
}
}
/**
* @param DataHandler $dataHandler
*/
public function processCmdmap_afterFinish(DataHandler $dataHandler) {
$visibilityFlagRepository = GeneralUtility::makeInstance(VisibilityFlagRepository::class);
$visibilityFlagRepository->fixAllLanguageParentUids();
}
/**
* Applies the given language data recursive.
*
......@@ -459,8 +484,7 @@ class TceMainHook {
* @return void
* @throws \InvalidArgumentException
*/
protected
function applyLanguageDataRecursive(
protected function applyLanguageDataRecursive(
$pageId, array $languageData, array $applyRecursive, $enableLogging, DataHandler $dataHandler
) {
$pageId = (int) $pageId;
......@@ -511,55 +535,4 @@ class TceMainHook {
}
}
/**
* This method is used to initialize new Elements with the default
*
* @param string $status
* @param string $table
* @param string $id
* @param array $fieldArray
* @param DataHandler $reference
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
*/
public
function processDatamap_afterDatabaseOperations(
$status, $table, $id, $fieldArray, &$reference
) {
if (in_array($table, VisibilityService::getSupportedTables(), TRUE)) {
if ($status === 'new') {
$row = [];
if (is_numeric($id) && $id > 0) {
$row['uid'] = $id;
} else {
$row['uid'] = $reference->substNEWwithIDs[$id];
}
/**
* copy the visibility flags of the parent pages
*/
if ($table === 'pages') {
$this->copyLanguageVisibilityFlagsFromParentPage((int) $row['uid']);
return;
}
}
CacheManager::getInstance()->flushAllCaches();
// Flush TYPO3 Caching Framework caches
GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)
->getCache('tx_languagevisibility')
->flush();
}
}
/**
* @param DataHandler $dataHandler
*/
public function processCmdmap_afterFinish(DataHandler $dataHandler) {
$visibilityFlagRepository = GeneralUtility::makeInstance(VisibilityFlagRepository::class);
$visibilityFlagRepository->fixAllLanguageParentUids();
}
}
......@@ -35,71 +35,12 @@ use TYPO3\Languagevisibility\Manager\CacheManager;
*/
class VisibilityFlagRepository {
const DB_TABLE = 'tx_languagevisibility_visibility_flag';
/**
* @var self
*/
protected static $instance;
const DB_TABLE = 'tx_languagevisibility_visibility_flag';
/**
* Returns a complete flag row or NULL if none is found
*
* @param $table
* @param $recordUid
* @param $lUid
* @return array|null
*/
public function getVisibilityFlag($table, $recordUid, $lUid): ?array {
$cacheManager = CacheManager::getInstance();
$cacheData = $cacheManager->get('visibilityFlagRowCache');
$isCacheEnabled = CacheManager::isCacheEnabled();
$cacheKey = $table . '_' . $recordUid . '_' . $lUid;
if (!$isCacheEnabled || !isset($cacheData[$cacheKey])) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(
self::DB_TABLE
);
$row = $queryBuilder->select('*')
->from(self::DB_TABLE)
->where(
$queryBuilder->expr()->eq(
'record_uid', $queryBuilder->createNamedParameter($table . '_' . $recordUid, \PDO::PARAM_STR)
)
)
->andWhere(
$queryBuilder->expr()->eq(
'record_table', $queryBuilder->createNamedParameter($table, \PDO::PARAM_STR)
)
)
->andWhere(
$queryBuilder->expr()->eq(
'record_language_uid', $queryBuilder->createNamedParameter($lUid, \PDO::PARAM_INT)
)
)
->execute()->fetch();
if ($row === FALSE) {
return NULL;
}
$cacheData[$cacheKey] = $row;
$cacheManager->set('visibilityFlagRowCache', $cacheData);
}
return $cacheData[$cacheKey];
}
/**
* @param $table
* @param $pid
* @param $lid
*/
/**
* Returns a complete flag row or NULL if none is found, fetched by default language element
*
......@@ -194,6 +135,58 @@ class VisibilityFlagRepository {
}
}
/**
* Returns a complete flag row or NULL if none is found
*
* @param $table
* @param $recordUid
* @param $lUid
* @return array|null
*/
public function getVisibilityFlag($table, $recordUid, $lUid): ?array {
$cacheManager = CacheManager::getInstance();
$cacheData = $cacheManager->get('visibilityFlagRowCache');
$isCacheEnabled = CacheManager::isCacheEnabled();
$cacheKey = $table . '_' . $recordUid . '_' . $lUid;
if (!$isCacheEnabled || !isset($cacheData[$cacheKey])) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(
self::DB_TABLE
);
$row = $queryBuilder->select('*')
->from(self::DB_TABLE)
->where(
$queryBuilder->expr()->eq(
'record_uid', $queryBuilder->createNamedParameter($table . '_' . $recordUid, \PDO::PARAM_STR)
)
)
->andWhere(
$queryBuilder->expr()->eq(
'record_table', $queryBuilder->createNamedParameter($table, \PDO::PARAM_STR)
)
)
->andWhere(
$queryBuilder->expr()->eq(
'record_language_uid', $queryBuilder->createNamedParameter($lUid, \PDO::PARAM_INT)
)
)
->execute()->fetch();
if ($row === FALSE) {
return NULL;
}
$cacheData[$cacheKey] = $row;
$cacheManager->set('visibilityFlagRowCache', $cacheData);
}
return $cacheData[$cacheKey];
}
/**
* Returns the uid of the default language parent row for a given element
*
......@@ -219,10 +212,10 @@ class VisibilityFlagRepository {
)
->execute()->fetch();
if($row['sys_language_uid'] > 0){
if ($row['sys_language_uid'] > 0) {
$uid = $row['uid'];
$defaultLanguageParentUid = $this->getDefaultLanguageParentUid($table, $uid);
}else{
} else {
$defaultLanguageParentUid = $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']];
}
......@@ -447,7 +440,6 @@ class VisibilityFlagRepository {
if ($correctLanguageParentUid > 0 && $correctLanguageParentUid !== $currentLanguageParentUid) {
unset($queryBuilder);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(
self::DB_TABLE
);
......
<?php
namespace TYPO3\Languagevisibility\Service;
use Exception;
use PDO;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
......@@ -32,7 +35,6 @@ use TYPO3\Languagevisibility\Utility\ExtensionUtility;
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
class BackendServices extends AbstractServices {
/**
......@@ -58,7 +60,7 @@ class BackendServices extends AbstractServices {
* @param int $languageUid
* @param boolean $omitLocal DEPRECATED since TYPO3 CMS 9 - is not used anymore because we only use the language visibility settings from the default language record
* @return bool
* @throws \Exception
* @throws Exception
*/
public static function isVisible(array $row, string $table, int $languageUid, bool $omitLocal = FALSE): bool {
......@@ -75,7 +77,7 @@ class BackendServices extends AbstractServices {
try {
$element = $elementfactory->getElementForTable($table, $row);
} catch ( \Exception $e ) {
} catch (Exception $e) {
return FALSE;
}
......@@ -97,23 +99,13 @@ class BackendServices extends AbstractServices {
public static function isOverlayRecord(array $row, string $table): bool {
$result = FALSE;
// todo: remove switch ?! page overlays doesn't exist anymore
switch ($table) {
case 'pages_language_overlay' :
$result = TRUE;
break;
case 'pages' :
default:
if (in_array($table, VisibilityService::getSupportedTables())) {
$tanslationIdField = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
if ($tanslationIdField !== '') {
// if the field which points to the orginal of the translation is
// not 0 a translation exists and we have an overlay record
$result = (int) $row[$tanslationIdField][0] !== 0;
}
}
break;
if (in_array($table, VisibilityService::getSupportedTables())) {
$tanslationIdField = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
if ($tanslationIdField !== '') {
// if the field which points to the orginal of the translation is
// not 0 a translation exists and we have an overlay record
$result = (int) $row[$tanslationIdField][0] !== 0;
}
}
return $result;
......@@ -130,7 +122,7 @@ class BackendServices extends AbstractServices {
* @param array $row
* @param string $cmd
* @return bool
* @throws \Exception
* @throws Exception
*/
public static function hasUserAccessToPageRecord(array $row, string $cmd = 'edit'): bool {
if ($cmd === 'new') {
......@@ -138,10 +130,10 @@ class BackendServices extends AbstractServices {
}
$rep = GeneralUtility::makeInstance(LanguageRepository::class);
$languages = $rep->getLanguages();
foreach ( $languages as $language ) {
foreach ($languages as $language) {
if (self::isVisible($row, 'pages', $language->getUid())) {
if (!$GLOBALS['BE_USER']->checkLanguageAccess($language->getUid())) {
//no access to a visible language: check fallbacks
//no access to a visible language: check fallbacks
$isInFallback = FALSE;
$fallbacks = $language->getFallbackOrder(self::getContextElement('pages', $row));
foreach ($fallbacks as $lId) {
......@@ -168,7 +160,7 @@ class BackendServices extends AbstractServices {
* @param string $table
* @param array $row
* @return bool
* @throws \Exception
* @throws Exception
*/
public static function hasUserAccessToEditRecord(string $table, array $row): bool {
if (!self::isSupportedTable($table)) {
......@@ -188,12 +180,12 @@ class BackendServices extends AbstractServices {
foreach ($languages as $language) {
if (self::isVisible($row, $table, $language->getUid())) {
if (!$GLOBALS['BE_USER']->checkLanguageAccess($language->getUid())) {
// no access to a visible language: check fallbacks
// no access to a visible language: check fallbacks
$isInFallback = FALSE;
$fallbacks = $language->getFallbackOrder(self::getContextElement($table, $row));
foreach ($fallbacks as $lId) {
if ($GLOBALS['BE_USER']->checkLanguageAccess($lId)) {
// TODO - write testcase - this can't be right
// TODO - write testcase - this can't be right
$isInFallback = TRUE;
continue;
}
......@@ -218,14 +210,13 @@ class BackendServices extends AbstractServices {
$elementfactory = GeneralUtility::makeInstance(ElementFactory::class);
try {
$element = $elementfactory->getElementForTable($table, $row);
} catch ( \Exception $e ) {
} catch (Exception $e) {
return '-';
}
return $element;
}
/**
* Method to check if the inheritance is enabled or not
*
......@@ -262,14 +253,16 @@ class BackendServices extends AbstractServices {
* @param Element $element
* @return array
*/
public static function getAvailableOptionsForLanguage(Language $language, bool $isOverlay = FALSE, Element $element = NULL): array {
public static function getAvailableOptionsForLanguage(
Language $language, bool $isOverlay = FALSE, Element $element = NULL
): array {
if ($element === NULL) {
$pid = GeneralUtility::_GP('id');
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
$row = $queryBuilder->select('*')
->from('pages')
->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT))
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($pid, PDO::PARAM_INT))
)
->setMaxResults(1)
->execute()->fetch();
......@@ -282,7 +275,7 @@ class BackendServices extends AbstractServices {
$select = [];
$useInheritance = ($elementSupportsInheritance && self::isInheritanceEnabled());
if (! $isOverlay) {
if (!$isOverlay) {
if ($uid === 0) {
$select['-'] = '-';
$select['yes'] = 'yes';
......@@ -301,14 +294,14 @@ class BackendServices extends AbstractServices {
}
}
//check permissions, if user has no permission only no for the language is allowed
// if the user has permissions for languages that act as fallbacklanguage: then the languages that falls back can have "-" in the options!
if (! $GLOBALS['BE_USER']->checkLanguageAccess($uid)) {
//check permissions, if user has no permission only no for the language is allowed
// if the user has permissions for languages that act as fallbacklanguage: then the languages that falls back can have "-" in the options!
if (!$GLOBALS['BE_USER']->checkLanguageAccess($uid)) {
//check if the language falls back to one of the languages the user has permissions:
//check if the language falls back to one of the languages the user has permissions:
$isInFallback = FALSE;
$fallbacks = $language->getFallbackOrder($element);
foreach ( $fallbacks as $lId ) {
foreach ($fallbacks as $lId) {
if ($GLOBALS['BE_USER']->checkLanguageAccess($lId)) {
$isInFallback = TRUE;
continue;
......@@ -328,7 +321,7 @@ class BackendServices extends AbstractServices {
}
}
} else {
//overlays elements can only have "force to no" or "force to no inherited"
//overlays elements can only have "force to no" or "force to no inherited"
$select['-'] = '-';
$select['no'] = 'no';
if ($useInheritance) {
......@@ -339,8 +332,11 @@ class BackendServices extends AbstractServices {
/**
* Get translations of labels from the locallang file
*/
foreach ( $select as $k => $v ) {
$select[$k] = LocalizationUtility::translate('LLL:EXT:languagevisibility/Resources/Private/Language/locallang_db.xlf:tx_languagevisibility_visibility.I.' . $v, 'languagevisibility');
foreach ($select as $k => $v) {
$select[$k] = LocalizationUtility::translate(
'LLL:EXT:languagevisibility/Resources/Private/Language/locallang_db.xlf:tx_languagevisibility_visibility.I.' . $v,
'languagevisibility'
);
}
return $select;
......@@ -356,9 +352,9 @@ class BackendServices extends AbstractServices {
/* @var $languageRep LanguageRepository */
$languageRep = GeneralUtility::makeInstance(LanguageRepository::class);
$languageList = $languageRep->getLanguages();
$default = array();
foreach ( $languageList as $language ) {
/** @var Language $language*/
$default = [];
foreach ($languageList as $language) {
/** @var Language $language */
$options = array_keys(self::getAvailableOptionsForLanguage($language));
$default[$language->getUid()] = array_shift($options);
}
......
......@@ -78,13 +78,15 @@ class FrontendServices extends AbstractServices {
public static function checkVisiblityForElement(array $row, string $table, int $lUid): bool {
$visibilityFlagRepository = GeneralUtility::makeInstance(VisibilityFlagRepository::class);
$visibilityFlag = $visibilityFlagRepository->preFetchVisibilityFlagDirectlyFromDatabase($table, $row['uid'], $lUid);
$visibilityFlag = $visibilityFlagRepository->preFetchVisibilityFlagDirectlyFromDatabase(
$table, $row['uid'], $lUid
);
if($visibilityFlag === '' || $visibilityFlag === '-'){
if ($visibilityFlag === '' || $visibilityFlag === '-') {
return TRUE;
}
if($visibilityFlag === 'no' || $visibilityFlag === 'no+'){
if ($visibilityFlag === 'no' || $visibilityFlag === 'no+') {
return FALSE;
}
......@@ -107,10 +109,7 @@ class FrontendServices extends AbstractServices {
* @return Element
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
*/
public
static function getElement(
array $row, string $table
) {
public static function getElement(array $row, string $table) {
$elementfactory = GeneralUtility::makeInstance(ElementFactory::class);
return $elementfactory->getElementForTable($table, $row);
}
......@@ -121,10 +120,7 @@ class FrontendServices extends AbstractServices {
* @return mixed
* @throws \Exception
*/
public
static function getOverlayLanguageIdForElement(
$element, $lUid
) {
public static function getOverlayLanguageIdForElement($element, $lUid) {
$languageRep = GeneralUtility::makeInstance(LanguageRepository::class);
$language = $languageRep->getLanguageById($lUid);
if (!$language instanceof Language) {
......@@ -144,10 +140,7 @@ class FrontendServices extends AbstractServices {
* @throws \ReflectionException
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
*/
public
static function getOverlayLanguageIdForElementRecord(
array $row, string $table, int $lUid
) {
public static function getOverlayLanguageIdForElementRecord(array $row, string $table, int $lUid) {
$reflect = new ReflectionClass(__CLASS__);
$cacheKey = implode('_', [$reflect->getShortName(), __FUNCTION__, $row['uid'], $table, $lUid]);
if (self::getCache()->has($cacheKey)) {
......@@ -176,10 +169,7 @@ class FrontendServices extends AbstractServices {
* @return mixed
* @throws \Exception
*/
public
static function getOverlayLanguageIdForElementRecordForced(
$uid, $table, $lUid
) {
public static function getOverlayLanguageIdForElementRecordForced($uid, $table, $lUid) {
$elementfactory = GeneralUtility::makeInstance(ElementFactory::class);
$element = $elementfactory->getElementForTable($table, $uid);
$languageRep = GeneralUtility::makeInstance(LanguageRepository::class);
......@@ -199,8 +189,7 @@ class FrontendServices extends AbstractServices {
* @return \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
*/
public
static function getCache() {
public static function getCache() {
if (!self::$cache) {
self::$cache = GeneralUtility::makeInstance(CacheManager::class)
->getCache('tx_languagevisibility');
......
......@@ -124,8 +124,7 @@ class VisibilityService implements SingletonInterface {
*/
public static function getSupportedTables() {
if (!isset(self::$supportedTables)) {
// todo: remove pages_language_overlay?
self::$supportedTables = ['pages', 'tt_content', 'tt_news', 'pages_language_overlay'];
self::$supportedTables = ['pages', 'tt_content', 'tt_news'];
if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['languagevisibility']['getElementForTable'])
&& is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['languagevisibility']['getElementForTable'])
......
......@@ -4,6 +4,8 @@ namespace TYPO3\Languagevisibility\Updates;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Install\Updates\DatabaseUpdatedPrerequisite;
use TYPO3\CMS\Core\Registry;
use TYPO3\CMS\Install\Updates\UpgradeWizardInterface;
use TYPO3\Languagevisibility\Repository\VisibilityFlagRepository;
use TYPO3\Languagevisibility\Service\VisibilityService;
......@@ -66,7 +68,6 @@ class VisibilitySettingsMigrationWizard implements UpgradeWizardInterface {
try {
//make sure the query-builder is fresh
unset($queryBuilder);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(
$table
);
......@@ -83,7 +84,6 @@ class VisibilitySettingsMigrationWizard implements UpgradeWizardInterface {
$row = $this->getRecord($table, $uid);
unset($queryBuilderVisibilityFlags);
$queryBuilderVisibilityFlags = GeneralUtility::makeInstance(
ConnectionPool::class
)->getQueryBuilderForTable(
......@@ -125,11 +125,8 @@ class VisibilitySettingsMigrationWizard implements UpgradeWizardInterface {
)
->execute();
}
//todo: empty languagevibsility field?
}
}
} catch (Exception $exception) {
continue;
}
......@@ -140,6 +137,13 @@ class VisibilitySettingsMigrationWizard implements UpgradeWizardInterface {
$this->visibilityFlagRepository->fixAllLanguageParentUids();
$this->visibilityFlagRepository->deleteDefaultFlags();
//mark wizard as done in registry
GeneralUtility::makeInstance(Registry::class)->set(
'installUpdate',
self::class,
TRUE
);
return TRUE;
}
......@@ -205,7 +209,7 @@ class VisibilitySettingsMigrationWizard implements UpgradeWizardInterface {
* @return mixed
*/
protected function getRecord($table, $uid) {
unset($queryBuilder);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(
$table
);
......@@ -228,6 +232,16 @@ class VisibilitySettingsMigrationWizard implements UpgradeWizardInterface {
*/
public function updateNecessary(): bool {
$wizardDone = GeneralUtility::makeInstance(Registry::class)->get(
'installUpdate',
self::class,
FALSE
);
if ($wizardDone) {
return FALSE;
}
$table = 'tx_languagevisibility_visibility_flag';
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(
$table
......@@ -238,11 +252,7 @@ class VisibilitySettingsMigrationWizard implements UpgradeWizardInterface {
->from($table)
->execute()->fetchAll();
if (count($rows) > 0) {
return FALSE;
}
return TRUE;
return !(count($rows) > 0);
}
/**
......@@ -254,5 +264,8 @@ class VisibilitySettingsMigrationWizard implements UpgradeWizardInterface {
* @return string[]
*/
public function getPrerequisites(): array {
return [
DatabaseUpdatedPrerequisite::class
];
}
}
......@@ -156,7 +156,7 @@ class FieldVisibilityUserFunction {
continue;
}
if(!$changeableElement->hasTranslation($language->getUid())){
if (!$changeableElement->hasTranslation($language->getUid())) {
continue;
}
......@@ -180,13 +180,12 @@ class FieldVisibilityUserFunction {
$language, $isOverlay, $changeableElement
);
// overlay here just means the default language record or a localization of the record for the given language //
// overlay here just means the default language record or a localization of the record for the given language
$overlay = $changeableElement->getOverLayRecordForCertainLanguage($language->getUid());
// if there is no overlay for the language, there is no point in displaying the visibility settings for the given language, since we can know the uid of the translated element yet
// if there is no overlay for the language, there is no point in displaying the visibility settings for the given language, since we can't know the uid of the translated element yet
if (is_array($overlay) && count($overlay) > 0) {
//$languageUid = $overlay['sys_language_uid'];
$overlayUid = $overlay['uid'];
//check if a flag for this localization/overlay has already been set
......@@ -215,7 +214,6 @@ class FieldVisibilityUserFunction {
],
'record_uid' => [
'name' => $nameBase . '[record_uid]',
//todo: fetch uid translated record
'value' => $changeableElement->getTable() . '_' . $overlay['uid']
],
'default_language_record_uid' => [
......@@ -238,8 +236,7 @@ class FieldVisibilityUserFunction {
$visibilityString = $currentOptionsForUserAndLanguage[$currentVisibilityFlag];
if ($this->isNewElement && $defaultSelect === ''
&& $this->modTSconfig['language.'][$language->getUid(
) . '.']['defaultVisibilityOnCreate'] !== ''
&& $this->modTSconfig['language.'][$language->getUid() . '.']['defaultVisibilityOnCreate'] !== ''
) {
$defaultSelect = $this->modTSconfig['language.'][$language->getUid() .
'.']['defaultVisibilityOnCreate'];
......@@ -264,20 +261,21 @@ class FieldVisibilityUserFunction {
<span class="checkbox-label-icon">
<span class="checkbox-label-icon-checked">
' . GeneralUtility::makeInstance(IconFactory::class)->getIcon(
'actions-check', Icon::SIZE_SMALL
)->render('inline') . '
'actions-check', Icon::SIZE_SMALL
)->render('inline') . '
</span>
<span class="checkbox-label-icon-unchecked">
' . GeneralUtility::makeInstance(IconFactory::class)->getIcon(
'empty-empty', Icon::SIZE_SMALL
)->render('inline') . '
'empty-empty', Icon::SIZE_SMALL
)->render('inline') . '
</span>
</span>
</label>
</div>';
// the enable logging info is required for each language now, therefore an hidden field is added for each language which is changed by the main enableLogging Checkbox
$hiddenEnableLoggingClass = 'contentElement-' . $changeableElement->getUid() . '-hiddenEnableLoggingInput';
$hiddenEnableLoggingClass = 'contentElement-' . $changeableElement->getUid(
) . '-hiddenEnableLoggingInput';
$infoitem['hiddenEnableLoggingInput'] = '<input type="hidden"
value="1"
name="' . $nameBase . '[enableLogging]"
......@@ -325,7 +323,8 @@ class FieldVisibilityUserFunction {
* @param array $nameArray
* @return string
*/
protected function getSelectBoxAndHiddenInputs($languageid, $select, $current, $nameArray): string {
protected function getSelectBoxAndHiddenInputs(int $languageid, array $select, string $current, array $nameArray
): string {
$content = '';
$addClassName = '';
if (count($select) === 1) {
......@@ -351,35 +350,6 @@ class FieldVisibilityUserFunction {
return $content;
}
/**
* Generates the selectbox for the languagevisibility settings of an item
*
* @param int $languageid
* @param array $select
* @param string $current current selected item
* @param string $name
* @return string
*/
protected function getSelectBox($languageid, $select, $current, $name): string {
$content = '';
$addClassName = '';
if (count($select) === 1) {
$addClassName = ' oneitem';
}
$content .= '<select class="form-control' . $addClassName . '" name="' . $name . '[' . $languageid . ']">';
foreach ($select as $skey => $svalue) {
$selected = '';
if ($current === $skey) {
$selected = 'selected="selected"';
}
$content .= '<option class="' . $this->getCSSClassFromVisibilityKey($skey) .
'" value="' . $skey . '" ' . $selected . '>' . $svalue . '</option>';
}
$content .= '</select>';
return $content;
}
/**
* This method is used to determine a css class for the diffrent visiblity modes
*
......@@ -448,8 +418,6 @@ class FieldVisibilityUserFunction {
'<td>' . $info['languageFlag'] . ' ' . $info['languageTitle'] . '</td>' .
'<td>' . $info['visibilityOptions'] . '</td>' .
'<td>' . $info['visibilityCurrently'] . '</td>' .
// '<td>' . $info['originalVisibility'] . '</td>' .
//'<td>' . $info['overlayVisibility'] . '</td>' .
'<td>' . $translationStatusIcon . '</td>' .
'<td>' . $visibilityStatusIcon . '</td>' .
($isPage && !$isOverlay ? '<td>' . $info['applyRecursiveCheckbox'] . ' ' . $info['hiddenEnableLoggingInput'] . $info['isVisibilityFlag'] . '</td>' : '') .
......
......@@ -45,23 +45,6 @@ call_user_func(
'foreign_field' => 'record_uid',
]
],
// todo: do we still need those two fields?
'tx_languagevisibility_inheritanceflag_original' => [
'exclude' => 1,
'label' => 'LLL:EXT:' . $extKey . '/Resources/Private/Language/locallang_db.xlf:pages.tx_languagevisibility_inheritanceflag_original',
'config' => [
'type' => 'check',
'default' => '0'
]
],
'tx_languagevisibility_inheritanceflag_overlayed' => [
'exclude' => 1,
'label' => 'LLL:EXT:' . $extKey . '/Resources/Private/Language/locallang_db.xlf:pages.tx_languagevisibility_inheritanceflag_overlayed',
'config' => [
'type' => 'check',
'default' => '0'
]
],
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns($table, $tempColumnsPages);
}, 'languagevisibility', 'pages'
......
......@@ -26,7 +26,7 @@ CREATE TABLE tt_content (
);
#
# Table structure for table 'tt_content'
# Table structure for table 'tx_languagevisibility_visibility_flag'
#
CREATE TABLE tx_languagevisibility_visibility_flag (
uid int(11) NOT NULL auto_increment,
......