Skip to content

Commit cb7b5ea

Browse files
fix: deliver news modal labels via AJAX so the dashboard widget shows the close label
1 parent ecdca18 commit cb7b5ea

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

Classes/Controller/DateController.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
1919
use TYPO3\CMS\Core\Http\JsonResponse;
2020
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
21+
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
2122
use Xima\XimaTypo3InternalNews\Configuration;
2223
use Xima\XimaTypo3InternalNews\Domain\Repository\NewsRepository;
2324
use Xima\XimaTypo3InternalNews\Service\DateService;
@@ -65,6 +66,7 @@ public function listAction(): JsonResponse
6566
'records' => $this->newsRepository->findAllByCurrentUser() ?? [],
6667
],
6768
),
69+
'labels' => $this->getModalLabels(),
6870
],
6971
);
7072
}
@@ -98,7 +100,22 @@ public function newsAction(): ResponseInterface
98100
'dateListCount' => (array_key_exists('dateListCount', $this->configuration) ? (int) $this->configuration['dateListCount'] : 20),
99101
],
100102
),
103+
'labels' => $this->getModalLabels(),
101104
],
102105
);
103106
}
107+
108+
/**
109+
* Modal labels resolved server-side so they are available regardless of the
110+
* (backend module / iframe) context the request runs in.
111+
*
112+
* @return array<string, string>
113+
*/
114+
private function getModalLabels(): array
115+
{
116+
return [
117+
'title' => (string) LocalizationUtility::translate('widget.title', 'XimaTypo3InternalNews'),
118+
'close' => (string) LocalizationUtility::translate('button.close', 'XimaTypo3InternalNews'),
119+
];
120+
}
104121
}

Resources/Public/JavaScript/utils.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class InternalNewsUtils {
88
.get()
99
.then(async (response) => {
1010
const resolved = await response.resolve();
11-
this.showInternalNews(TYPO3.lang !== undefined ? TYPO3.lang['internal_news.title'] : 'Internal News', resolved.result);
11+
this.showInternalNews(this.title(resolved.labels), resolved.result, resolved.labels);
1212
});
1313
}
1414

@@ -17,12 +17,14 @@ class InternalNewsUtils {
1717
.get()
1818
.then(async (response) => {
1919
const resolved = await response.resolve();
20-
this.showInternalNewsList(TYPO3.lang !== undefined ? TYPO3.lang['internal_news.title'] : 'Internal News', resolved.result);
20+
this.showInternalNewsList(this.title(resolved.labels), resolved.result, resolved.labels);
2121
});
2222
}
2323

24-
closeButton = () => ({
25-
text: TYPO3.lang !== undefined ? TYPO3.lang['internal_news.close'] : 'Close',
24+
title = (labels) => labels?.title ?? TYPO3.lang?.['internal_news.title'] ?? 'Internal News';
25+
26+
closeButton = (labels) => ({
27+
text: labels?.close ?? TYPO3.lang?.['internal_news.close'] ?? 'Close',
2628
name: 'close',
2729
icon: 'actions-close',
2830
active: true,
@@ -32,18 +34,18 @@ class InternalNewsUtils {
3234
}
3335
})
3436

35-
showInternalNews = (title, description) => {
37+
showInternalNews = (title, description, labels) => {
3638
Modal.advanced({
3739
title: title,
3840
content: document.createRange()
3941
.createContextualFragment(description),
4042
size: {width: Modal.sizes.medium, height: Modal.sizes.default},
4143
staticBackdrop: true,
42-
buttons: [this.closeButton()]
44+
buttons: [this.closeButton(labels)]
4345
});
4446
}
4547

46-
showInternalNewsList = (title, content) => {
48+
showInternalNewsList = (title, content, labels) => {
4749
Modal.advanced({
4850
title: title,
4951
content: document.createRange()
@@ -61,7 +63,7 @@ class InternalNewsUtils {
6163
});
6264
});
6365
},
64-
buttons: [this.closeButton()]
66+
buttons: [this.closeButton(labels)]
6567
});
6668
}
6769
}

0 commit comments

Comments
 (0)