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
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Team23\T23InlineContainer\Backend\FormDataProvider;

use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class ContainerChildrenLanguageCorrectionFormDataProvider implements FormDataProviderInterface
{
public function addData(array $result): array
{
if (empty($result["processedTca"]["columns"]["tx_t23inlinecontainer_elements"])) {
return $result;
}

$registeredCTypes = GeneralUtility::makeInstance(\B13\Container\Tca\Registry::class)->getRegisteredCTypes();
$cType = $result['databaseRow']['CType'][0] ?? '';
if (!in_array($cType, $registeredCTypes, true)) {
return $result;
}

$parentLanguageUid = (int)$result['databaseRow']['sys_language_uid'] ?? 0;

$children =& $result['processedTca']['columns']['tx_t23inlinecontainer_elements']['children'];
$translationsExistFor = [];

// store ids of original language elements that have a translation
foreach ($children as &$child) {
$lang = (int)$child['databaseRow']['sys_language_uid'] ?? 0;
$origUid = (int)($child['databaseRow']['l18n_parent'][0] ?? 0);
if ($parentLanguageUid === 0 && $lang > 0) {
continue;
}
if ($parentLanguageUid > 0 && $lang === $parentLanguageUid && $origUid > 0) {
$translationsExistFor[] = $origUid;
}
// if child language differs from parents language, grey out child in backend
$child['isInlineDefaultLanguageRecordInLocalizedParentContext'] = ($lang !== $parentLanguageUid);
}

$filteredChildren = [];

foreach ($children as $i => &$child) {
$lang = (int)$child['databaseRow']['sys_language_uid'] ?? 0;
//$child['defaultLanguageDiffRow'] = null;

// hide translated elements from default language view
if ($parentLanguageUid === 0 && $lang > 0) {
continue;
}

// hide original language children when they have a translated element
$childUid = (int)($child['databaseRow']['uid'] ?? 0);
if (in_array($childUid, $translationsExistFor, true)) {
continue;
}

$filteredChildren[] = $child;
}
$children = array_values($filteredChildren);

return $result;
}
}
40 changes: 40 additions & 0 deletions Classes/Hooks/DataHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,46 @@ public function processDatamap_beforeStart(\TYPO3\CMS\Core\DataHandling\DataHand
}
}

/**
* @param array $incomingFieldArray
* @param string $table
* @param int|string $id
* @param \TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler
* @return void
*/
public function processDatamap_preProcessFieldArray(
array &$incomingFieldArray,
string $table,
$id,
\TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler
): void {
// Only handle content elements
if ($table !== 'tt_content') {
return;
}

// Only relevant if this is a translated record
$languageUid = (int)($incomingFieldArray['sys_language_uid'] ?? 0);
if ($languageUid <= 0) {
return;
}

// If this record has a container parent, check if it's a localized one
$txContainerParent = (int)($incomingFieldArray['tx_container_parent'] ?? 0);
if ($txContainerParent > 0) {
// Fetch the parent record
$parentRecord = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('tt_content', $txContainerParent);

// If parent exists and is a localized record, resolve its default language UID
if (!empty($parentRecord['l18n_parent'])) {
$defaultParentUid = (int)$parentRecord['l18n_parent'];

// Rewrite to the default-language container
$incomingFieldArray['tx_container_parent'] = $defaultParentUid;
}
}
}

public function processCmdmap_preProcess($command, $table, $id, $value, $pObj, $pasteUpdate)
{
if (in_array($command, ['copy', 'localize']) && $table === 'tt_content') {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license": "GPL-2.0-or-later",
"require": {
"typo3/cms-core": "^11.5 || ^12.4",
"b13/container": "^2.3.1"
"b13/container": "^2.3 || ^3.1"
},
"suggest": {
"georgringer/news": "Most usefull application of this extension."
Expand Down
4 changes: 2 additions & 2 deletions ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
'author_company' => 'TEAM23',
'state' => 'beta',
'clearCacheOnLoad' => true,
'version' => '0.0.13',
'version' => '0.0.14',
'constraints' => [
'depends' => [
'typo3' => '11.0.0-12.9.99',
'container' => '2.3.1-2.9.99',
'container' => '2.3.1-3.9.99',
],
'conflicts' => [
],
Expand Down
9 changes: 7 additions & 2 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* LICENSE.txt file that was distributed with this source code.
*/

$GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass']['tx-t23inlinecontainer'] = 'Team23\T23InlineContainer\Hooks\DataHandler';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass']['tx-t23inlinecontainer'] = 'Team23\T23InlineContainer\Hooks\DataHandler';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass']['tx-t23inlinecontainer'] = 'Team23\T23InlineContainer\Hooks\DataHandler';

$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['tcaDatabaseRecord'][\Team23\T23InlineContainer\Backend\FormDataProvider\ContainerChildrenFormDataProvider::class] = [
Expand All @@ -19,4 +19,9 @@
'before' => [
\TYPO3\CMS\Backend\Form\FormDataProvider\InlineOverrideChildTca::class,
]
];
];
$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['tcaDatabaseRecord'][\Team23\T23InlineContainer\Backend\FormDataProvider\ContainerChildrenLanguageCorrectionFormDataProvider::class] = [
'depends' => [
\TYPO3\CMS\Backend\Form\FormDataProvider\TcaInlineData::class,
],
];