‪TYPO3CMS  ‪main
AbstractTableHandler.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use TYPO3\CMS\Backend\Utility\BackendUtility;
25 
32 {
36  protected ‪$tableName;
37 
44  public function ‪match(string ‪$tableName): bool
45  {
47  }
48 
53  protected function ‪generateTranslatedRecords(string ‪$tableName, $fieldValues): void
54  {
55  if (!BackendUtility::isTableLocalizable(‪$tableName)) {
56  return;
57  }
58 
59  $recordFinder = GeneralUtility::makeInstance(RecordFinder::class);
60  $demoLanguages = $recordFinder->findIdsOfDemoLanguages();
61 
62  $translatedRecord = -42;
63  foreach ($demoLanguages as $demoLanguageIndex => $demoLanguageUid) {
64  switch ($demoLanguageIndex) {
65  case 0:
66  // danish: 'copy / free mode', l10n_parent = 0, l10n_source = default lang record
67  $this->‪copyRecordToLanguage($tableName, $fieldValues['uid'], $demoLanguageUid);
68  break;
69  case 1:
70  // german: 'translate / connected mode', l10n_parent = default lang record, l10n_source = default lang record
71  $result = $this->‪localizeRecord($tableName, $fieldValues['uid'], $demoLanguageUid);
72  $translatedRecord = $result[‪$tableName][$fieldValues['uid']];
73  break;
74  case 2:
75  // french: 'translate / connected mode' german as source, l10n_parent = default lang record, source = german record
76  $result = $this->‪localizeRecord($tableName, $translatedRecord, $demoLanguageUid);
77  $translatedRecord = $result[‪$tableName][$translatedRecord];
78  break;
79  case 3:
80  // spanish: 'copy mode / free mode', french as source, l10n_parent = default lang record, source = french record
81  $this->‪copyRecordToLanguage($tableName, $translatedRecord, $demoLanguageUid);
82  break;
83  default:
84  throw new ‪Exception(
85  'Unknown language. No idea what to do with language ' . (int)$demoLanguageUid . ' for table ' . ‪$tableName,
86  1597437985
87  );
88  }
89  }
90  }
91 
100  protected function ‪localizeRecord(‪$tableName, ‪$uid, $languageId)
101  {
102  $commandMap = [
103  ‪$tableName => [
104  ‪$uid => [
105  'localize' => $languageId,
106  ],
107  ],
108  ];
109  $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
110  $dataHandler->enableLogging = false;
111  $dataHandler->start([], $commandMap);
112  $dataHandler->process_cmdmap();
113  return $dataHandler->copyMappingArray;
114  }
115 
124  protected function ‪copyRecordToLanguage(‪$tableName, ‪$uid, $languageId)
125  {
126  $commandMap = [
127  ‪$tableName => [
128  ‪$uid => [
129  'copyToLanguage' => $languageId,
130  ],
131  ],
132  ];
133  $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
134  $dataHandler->enableLogging = false;
135  $dataHandler->start([], $commandMap);
136  $dataHandler->process_cmdmap();
137  return $dataHandler->copyMappingArray;
138  }
139 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:104
‪TYPO3\CMS\Styleguide\TcaDataGenerator\TableHandler\AbstractTableHandler
Definition: AbstractTableHandler.php:32
‪TYPO3\CMS\Styleguide\TcaDataGenerator\TableHandler
Definition: AbstractTableHandler.php:18
‪TYPO3\CMS\Styleguide\TcaDataGenerator\TableHandler\AbstractTableHandler\match
‪bool match(string $tableName)
Definition: AbstractTableHandler.php:43
‪TYPO3\CMS\Styleguide\TcaDataGenerator\TableHandler\AbstractTableHandler\localizeRecord
‪array localizeRecord($tableName, $uid, $languageId)
Definition: AbstractTableHandler.php:99
‪TYPO3\CMS\Styleguide\TcaDataGenerator\TableHandler\AbstractTableHandler\copyRecordToLanguage
‪array copyRecordToLanguage($tableName, $uid, $languageId)
Definition: AbstractTableHandler.php:123
‪TYPO3\CMS\Styleguide\TcaDataGenerator\TableHandler\AbstractTableHandler\$tableName
‪string $tableName
Definition: AbstractTableHandler.php:35
‪TYPO3\CMS\Webhooks\Message\$uid
‪identifier readonly int $uid
Definition: PageModificationMessage.php:35
‪TYPO3\CMS\Styleguide\TcaDataGenerator\Exception
Definition: Exception.php:25
‪TYPO3\CMS\Styleguide\TcaDataGenerator\TableHandler\AbstractTableHandler\generateTranslatedRecords
‪generateTranslatedRecords(string $tableName, $fieldValues)
Definition: AbstractTableHandler.php:52
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Styleguide\TcaDataGenerator\RecordFinder
Definition: RecordFinder.php:38