Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Classes/Model/L10nAccumulatedInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
79 changes: 79 additions & 0 deletions Classes/Model/Tools/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
* @author Kasper Skaarhoj <kasperYYYY@typo3.com>
*/

use Localizationteam\L10nmgr\Constants;
use Localizationteam\L10nmgr\LanguageRestriction\Collection\LanguageRestrictionCollection;
use Localizationteam\L10nmgr\Traits\BackendUserTrait;
use PDO;
use TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider;
Expand Down Expand Up @@ -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;
}
}
20 changes: 18 additions & 2 deletions Configuration/TCA/tx_l10nmgr_cfg.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => ''],
Expand Down Expand Up @@ -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' => ''],
Expand Down
3 changes: 3 additions & 0 deletions Resources/Private/Language/locallang_db.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
<trans-unit id="tx_l10nmgr_cfg.include" xml:space="preserve">
<source>Include elements (comma list of &quot;table:uid&quot; pairs):</source>
</trans-unit>
<trans-unit id="tx_l10nmgr_cfg.applyExcludeToChildren" xml:space="preserve">
<source>Exclude children of excluded parent elements (IRRE, sys_file_reference):</source>
</trans-unit>
<trans-unit id="tx_l10nmgr_cfg.metadata" xml:space="preserve">
<source>Additional Metadata (JSON formatted key value pairs):</source>
</trans-unit>
Expand Down
1 change: 1 addition & 0 deletions ext_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down