|
5 | 5 | namespace Xima\XimaTypo3FrontendEdit\Service; |
6 | 6 |
|
7 | 7 | use TYPO3\CMS\Backend\Routing\UriBuilder; |
| 8 | +use TYPO3\CMS\Backend\Utility\BackendUtility; |
8 | 9 | use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; |
9 | 10 | use TYPO3\CMS\Core\Core\Bootstrap; |
10 | 11 | use TYPO3\CMS\Core\EventDispatcher\EventDispatcher; |
@@ -231,31 +232,48 @@ private function processNewButton(Button &$button, string $identifier, ButtonTyp |
231 | 232 | ), $identifier); |
232 | 233 | } |
233 | 234 |
|
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 |
235 | 236 | { |
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 | + ) { |
237 | 240 | $button->appendChild(new Button( |
238 | 241 | 'LLL:EXT:xima_typo3_frontend_edit/Resources/Private/Language/locallang.xlf:div_data', |
239 | 242 | ButtonType::Divider |
240 | 243 | ), 'div_data'); |
241 | 244 |
|
242 | | - foreach ($data[$contentElement['uid']] as $key => $dataEntry) { |
| 245 | + foreach ($data[$uid] as $key => $dataEntry) { |
243 | 246 | if (!$dataEntry['label'] || !(($dataEntry['table'] && $dataEntry['uid']) || ($dataEntry['url']))) { |
244 | 247 | continue; |
245 | 248 | } |
246 | 249 |
|
| 250 | + $recordUid = null; |
247 | 251 | if ($dataEntry['table'] && $dataEntry['uid']) { |
248 | 252 | if (!$backendUser->recordEditAccessInternals($dataEntry['table'], $dataEntry['uid'])) { |
249 | 253 | continue; |
250 | 254 | } |
| 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 | + } |
251 | 269 | } |
252 | 270 |
|
253 | 271 | $url = $dataEntry['url'] ?: GeneralUtility::makeInstance(UriBuilder::class)->buildUriFromRoute( |
254 | 272 | 'record_edit', |
255 | 273 | [ |
256 | 274 | 'edit' => [ |
257 | 275 | $dataEntry['table'] => [ |
258 | | - $dataEntry['uid'] => 'edit', |
| 276 | + $recordUid => 'edit', |
259 | 277 | ], |
260 | 278 | 'language' => $languageUid, |
261 | 279 | ], |
|
0 commit comments