diff --git a/Classes/Model/L10nAccumulatedInformation.php b/Classes/Model/L10nAccumulatedInformation.php index ae01729f..256314f5 100644 --- a/Classes/Model/L10nAccumulatedInformation.php +++ b/Classes/Model/L10nAccumulatedInformation.php @@ -303,6 +303,40 @@ protected function _calculateInternalAccumulatedInformationsArray() continue; } + // Restrictions are only defined on default lang + if ((int)$l10ncfg['applyExcludeToChildren'] === 1 && $t8Tools->isParentItemExcluded($table, $row, $sysLang)) { + continue; + } + + // Check parent state of inline Elements and sys_file_references using the row or the rowPrevLang variable + if ((int)$l10ncfg['applyExcludeToChildren'] === 1 && $this->noHidden) { + // Check hidden state in default language + if ($t8Tools->isParentItemHidden($table, $row, $sysLang)) { + continue; + } + + // Get translation overlay record to check for hidden parents in forced source language + $prevLangInfo = $t8Tools->translationInfo( + $table, + $row['uid'], + $previewLanguage, + null, + '', + $previewLanguage + ); + if (!empty($prevLangInfo) && $prevLangInfo['translations'][$previewLanguage]) { + $rowPrevLang = BackendUtility::getRecordWSOL( + $prevLangInfo['translation_table'], + $prevLangInfo['translations'][$previewLanguage]['uid'] + ); + + // Hidden state for + if (!empty($rowPrevLang) && $t8Tools->isParentItemHidden($table, $rowPrevLang, $sysLang)) { + continue; + } + } + } + $accum[$pageId]['items'][$table][$row['uid']] = $t8Tools->translationDetails( $table, $row, diff --git a/Classes/Model/Tools/Tools.php b/Classes/Model/Tools/Tools.php index f490c7bd..dd6d8c38 100644 --- a/Classes/Model/Tools/Tools.php +++ b/Classes/Model/Tools/Tools.php @@ -26,6 +26,8 @@ * @author Kasper Skaarhoj */ +use Localizationteam\L10nmgr\Constants; +use Localizationteam\L10nmgr\LanguageRestriction\Collection\LanguageRestrictionCollection; use Localizationteam\L10nmgr\Traits\BackendUserTrait; use PDO; use TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider; @@ -1650,4 +1652,81 @@ public function flushTranslations($table, $uid, $exec = false) } return [$remove, $TCEmain_cmd, $TCEmain_data, $errorLog]; } + + private function getParentTables(string $table, array $row): array + { + $isInlineTable = (is_array($inlineTablesConfig = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['l10nmgr']['inlineTablesConfig']) && array_key_exists( + $table, + $inlineTablesConfig + )); + + if ($isInlineTable) { + // Parent fields: + return ['tt_content', $inlineTablesConfig[$table]['parentField']]; + } + + if ($table === 'sys_file_reference') { + return [$row['tablenames'], 'uid_foreign']; + } + + return [null, null]; + } + + public function isParentItemHidden(string $table, array $row, int $sysLang): bool + { + [$parentTable, $parentField] = $this->getParentTables($table, $row); + + if (!empty($parentTable) && !empty($parentField)) { + if ($parentTable === 'pages') { + return false; + } + + $parent = BackendUtility::getRecordWSOL($parentTable, (int)$row[$parentField]); + + if ($parent['hidden']) { + return true; + } + + // Exclude item if parent is missing + if (!$parent) { + return true; + } + + // Recursive call for nested inline elements and sys_file_references + return $this->isParentItemHidden($parentTable, $parent, $sysLang); + } + + return false; + } + + public function isParentItemExcluded(string $table, array $row, int $sysLang): bool + { + [$parentTable, $parentField] = $this->getParentTables($table, $row); + + if (!empty($parentTable) && !empty($parentField)) { + $parent = BackendUtility::getRecordWSOL($parentTable, (int)$row[$parentField]); + if (!empty($parent[Constants::L10NMGR_LANGUAGE_RESTRICTION_FIELDNAME])) { + /** @var LanguageRestrictionCollection $languageIsRestricted */ + $languageIsRestricted = LanguageRestrictionCollection::load( + $sysLang, + true, + $parentTable, + Constants::L10NMGR_LANGUAGE_RESTRICTION_FIELDNAME + ); + if ($languageIsRestricted->hasItem((int)$parent['uid'])) { + return true; + } + } + + // Exclude item if parent is missing + if (!$parent) { + return true; + } + + // Recursive call for nested inline elements and sys_file_references + return $this->isParentItemExcluded($parentTable, $parent, $sysLang); + } + + return false; + } } diff --git a/Configuration/TCA/tx_l10nmgr_cfg.php b/Configuration/TCA/tx_l10nmgr_cfg.php index 3f91139a..a73e3495 100644 --- a/Configuration/TCA/tx_l10nmgr_cfg.php +++ b/Configuration/TCA/tx_l10nmgr_cfg.php @@ -204,9 +204,17 @@ 'default' => 0, ], ], + 'applyExcludeToChildren' => [ + 'exclude' => 1, + 'label' => $l10n . ':tx_l10nmgr_cfg.applyExcludeToChildren', + 'config' => [ + 'type' => 'check', + 'default' => 0, + ], + ], ], 'types' => [ - 0 => ['showitem' => 'title,filenameprefix, depth, pages, sourceLangStaticId, --palette--;;forcedSourceLanguageSettings, targetLanguages, tablelist, exclude, include, metadata, displaymode, incfcewithdefaultlanguage, pretranslatecontent, overrideexistingtranslations, sortexports'], + 0 => ['showitem' => 'title,filenameprefix, depth, pages, sourceLangStaticId, --palette--;;forcedSourceLanguageSettings, targetLanguages, tablelist, exclude, include, metadata, displaymode, incfcewithdefaultlanguage, pretranslatecontent, overrideexistingtranslations, sortexports, applyExcludeToChildren'], ], 'palettes' => [ '1' => ['showitem' => ''], @@ -403,9 +411,17 @@ 'default' => 0, ], ], + 'applyExcludeToChildren' => [ + 'exclude' => 1, + 'label' => $l10n . ':tx_l10nmgr_cfg.applyExcludeToChildren', + 'config' => [ + 'type' => 'check', + 'default' => 0, + ], + ], ], 'types' => [ - 0 => ['showitem' => 'title,filenameprefix, depth, pages, --palette--;;forcedSourceLanguageSettings, targetLanguages, tablelist, exclude, include, metadata, displaymode, incfcewithdefaultlanguage, pretranslatecontent, overrideexistingtranslations, sortexports'], + 0 => ['showitem' => 'title,filenameprefix, depth, pages, --palette--;;forcedSourceLanguageSettings, targetLanguages, tablelist, exclude, include, metadata, displaymode, incfcewithdefaultlanguage, pretranslatecontent, overrideexistingtranslations, sortexports, applyExcludeToChildren'], ], 'palettes' => [ '1' => ['showitem' => ''], diff --git a/Resources/Private/Language/locallang_db.xlf b/Resources/Private/Language/locallang_db.xlf index 5c93db70..b27cca37 100644 --- a/Resources/Private/Language/locallang_db.xlf +++ b/Resources/Private/Language/locallang_db.xlf @@ -76,6 +76,9 @@ Include elements (comma list of "table:uid" pairs): + + Exclude children of excluded parent elements (IRRE, sys_file_reference): + Additional Metadata (JSON formatted key value pairs): diff --git a/ext_tables.sql b/ext_tables.sql index d75201de..e5250a46 100644 --- a/ext_tables.sql +++ b/ext_tables.sql @@ -25,6 +25,7 @@ CREATE TABLE tx_l10nmgr_cfg overrideexistingtranslations tinyint(4) DEFAULT '0', pretranslatecontent tinyint(4) DEFAULT '0', sortexports tinyint(4) DEFAULT '0', + applyExcludeToChildren tinyint(4) DEFAULT '0', PRIMARY KEY (uid), KEY parent (pid)