Skip to content

Commit 094604e

Browse files
author
Konrad Michalik
authored
Merge pull request #26 from xima-media/fix-additonal-translated-record
fix: handle additional data to support translated records
2 parents 4b7377a + 5d4ae88 commit 094604e

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

Classes/Service/MenuGenerator.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Xima\XimaTypo3FrontendEdit\Service;
66

77
use TYPO3\CMS\Backend\Routing\UriBuilder;
8+
use TYPO3\CMS\Backend\Utility\BackendUtility;
89
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
910
use TYPO3\CMS\Core\Core\Bootstrap;
1011
use TYPO3\CMS\Core\EventDispatcher\EventDispatcher;
@@ -231,31 +232,48 @@ private function processNewButton(Button &$button, string $identifier, ButtonTyp
231232
), $identifier);
232233
}
233234

234-
private function handleAdditionalData(Button &$button, array $contentElement, array $contentElementConfig, array $data, BackendUserAuthentication $backendUser, int $languageUid, string $returnUrlAnchor): void
235+
private function handleAdditionalData(Button $button, array $contentElement, array $contentElementConfig, array $data, BackendUserAuthentication $backendUser, int $languageUid, string $returnUrlAnchor): void
235236
{
236-
if (array_key_exists($contentElement['uid'], $data) && !empty($data[$contentElement['uid']])) {
237+
if ((array_key_exists($contentElement['uid'], $data) && ($uid = $contentElement['uid']) && !empty($data[$uid])) ||
238+
(array_key_exists('l10n_source', $contentElement) && array_key_exists($contentElement['l10n_source'], $data) && ($uid = $contentElement['l10n_source'])&& !empty($data[$uid]))
239+
) {
237240
$button->appendChild(new Button(
238241
'LLL:EXT:xima_typo3_frontend_edit/Resources/Private/Language/locallang.xlf:div_data',
239242
ButtonType::Divider
240243
), 'div_data');
241244

242-
foreach ($data[$contentElement['uid']] as $key => $dataEntry) {
245+
foreach ($data[$uid] as $key => $dataEntry) {
243246
if (!$dataEntry['label'] || !(($dataEntry['table'] && $dataEntry['uid']) || ($dataEntry['url']))) {
244247
continue;
245248
}
246249

250+
$recordUid = null;
247251
if ($dataEntry['table'] && $dataEntry['uid']) {
248252
if (!$backendUser->recordEditAccessInternals($dataEntry['table'], $dataEntry['uid'])) {
249253
continue;
250254
}
255+
$recordUid = $dataEntry['uid'];
256+
257+
/*
258+
* Check if the record is translated and if so, get the translation
259+
*/
260+
$record = BackendUtility::getRecord($dataEntry['table'], $recordUid);
261+
if ($record && array_key_exists('sys_language_uid', $record) && $record['sys_language_uid'] !== $languageUid) {
262+
$record = ContentUtility::getTranslatedRecord($dataEntry['table'], $recordUid, $languageUid);
263+
if ($record) {
264+
$recordUid = $record['uid'];
265+
} else {
266+
continue;
267+
}
268+
}
251269
}
252270

253271
$url = $dataEntry['url'] ?: GeneralUtility::makeInstance(UriBuilder::class)->buildUriFromRoute(
254272
'record_edit',
255273
[
256274
'edit' => [
257275
$dataEntry['table'] => [
258-
$dataEntry['uid'] => 'edit',
276+
$recordUid => 'edit',
259277
],
260278
'language' => $languageUid,
261279
],

Classes/Utility/ContentUtility.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ public static function fetchContentElements(int $pid, int $languageUid): array
2828
->executeQuery()->fetchAllAssociative();
2929
}
3030

31+
public static function getTranslatedRecord(string $table, int $parendUid, int $languageUid): array|bool
32+
{
33+
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
34+
35+
return $queryBuilder
36+
->select('*')
37+
->from($table)
38+
->where(
39+
$queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($parendUid, Connection::PARAM_INT)),
40+
$queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter($languageUid, Connection::PARAM_INT)),
41+
)
42+
->executeQuery()->fetchAssociative();
43+
}
3144
public static function getContentElementConfig(string $cType, string $listType): array|bool
3245
{
3346
$tca = $cType === 'list' ? $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] : $GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'];

0 commit comments

Comments
 (0)