2 declare(strict_types = 1);
19 use Psr\Http\Message\ResponseInterface;
20 use Psr\Http\Message\ServerRequestInterface;
65 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
66 $this->localizationRepository = GeneralUtility::makeInstance(LocalizationRepository::class);
77 $params = $request->getQueryParams();
78 if (!isset($params[
'pageId'], $params[
'languageId'])) {
82 $pageId = (int)$params[
'pageId'];
83 $languageId = (int)$params[
'languageId'];
86 $translationProvider = GeneralUtility::makeInstance(TranslationConfigurationProvider::class);
87 $systemLanguages = $translationProvider->getSystemLanguages($pageId);
89 $availableLanguages = [];
92 $elementsInColumnCount = $this->localizationRepository->getLocalizedRecordCount($pageId, $languageId);
94 if ($elementsInColumnCount === 0) {
95 $fetchedAvailableLanguages = $this->localizationRepository->fetchAvailableLanguages($pageId, $languageId);
96 foreach ($fetchedAvailableLanguages as $language) {
97 if (isset($systemLanguages[$language[
'sys_language_uid']])) {
98 $availableLanguages[] = $systemLanguages[$language[
'sys_language_uid']];
102 $result = $this->localizationRepository->fetchOriginLanguage($pageId, $languageId);
103 $availableLanguages[] = $systemLanguages[$result[
'sys_language_uid']];
107 foreach ($availableLanguages as &$language) {
108 if ($language[
'flagIcon'] ===
'empty-empty') {
109 $language[
'flagIcon'] =
'';
111 $language[
'flagIcon'] = $this->iconFactory->getIcon($language[
'flagIcon'],
Icon::SIZE_SMALL)->render();
115 return (
new JsonResponse())->setPayload($availableLanguages);
126 $params = $request->getQueryParams();
127 if (!isset($params[
'pageId'], $params[
'destLanguageId'], $params[
'languageId'])) {
128 return new JsonResponse(
null, 400);
131 $pageId = (int)$params[
'pageId'];
132 $destLanguageId = (int)$params[
'destLanguageId'];
133 $languageId = (int)$params[
'languageId'];
136 $result = $this->localizationRepository->getRecordsToCopyDatabaseResult(
143 while ($row = $result->fetch()) {
148 $colPos = $row[
'colPos'];
149 if (!isset($records[$colPos])) {
150 $records[$colPos] = [];
152 $records[$colPos][] = [
153 'icon' => $this->iconFactory->getIconForRecord(
'tt_content', $row,
Icon::SIZE_SMALL)->render(),
154 'title' => $row[
$GLOBALS[
'TCA'][
'tt_content'][
'ctrl'][
'label']],
159 return (
new JsonResponse())->setPayload([
160 'records' => $records,
169 public function localizeRecords(ServerRequestInterface $request): ResponseInterface
171 $params = $request->getQueryParams();
172 if (!isset($params[
'pageId'], $params[
'srcLanguageId'], $params[
'destLanguageId'], $params[
'action'], $params[
'uidList'])) {
173 return new JsonResponse(
null, 400);
176 if ($params[
'action'] !== static::ACTION_COPY && $params[
'action'] !== static::ACTION_LOCALIZE) {
177 $response =
new Response(
'php://temp', 400, [
'Content-Type' =>
'application/json; charset=utf-8']);
178 $response->getBody()->write(
'Invalid action "' . $params[
'action'] .
'" called.');
184 (
int)$params[
'pageId'],
185 (
int)$params[
'destLanguageId'],
186 (
int)$params[
'srcLanguageId'],
192 return (
new JsonResponse())->setPayload([]);
209 array $transmittedUidList
212 $validUidList = $this->localizationRepository->getRecordsToCopyDatabaseResult(
219 return array_intersect(array_unique($transmittedUidList), array_column($validUidList->fetchAll(),
'uid'));
227 protected function process($params): void
229 $destLanguageId = (int)$params[
'destLanguageId'];
236 if (isset($params[
'uidList']) && is_array($params[
'uidList'])) {
237 foreach ($params[
'uidList'] as $currentUid) {
238 if ($params[
'action'] === static::ACTION_LOCALIZE) {
239 $cmd[
'tt_content'][$currentUid] = [
240 'localize' => $destLanguageId
243 $cmd[
'tt_content'][$currentUid] = [
244 'copyToLanguage' => $destLanguageId,
250 $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
251 $dataHandler->start([], $cmd);
252 $dataHandler->process_cmdmap();
262 $backendLayoutView = GeneralUtility::makeInstance(BackendLayoutView::class);
263 $backendLayouts = $backendLayoutView->getSelectedBackendLayout($pageId);
265 foreach ($backendLayouts[
'__items'] as $backendLayout) {
266 $columns[(int)$backendLayout[1]] = $backendLayout[0];
270 'columns' => $columns,
271 'columnList' => $backendLayouts[
'__colPosList'],