Skip to content

Instantly share code, notes, and snippets.

@Tuurlijk
Created January 21, 2022 15:36
Show Gist options
  • Save Tuurlijk/34d989e86d5e4235d9069a1a18f4a293 to your computer and use it in GitHub Desktop.
Save Tuurlijk/34d989e86d5e4235d9069a1a18f4a293 to your computer and use it in GitHub Desktop.
Populate l10n_state field of tt_content records when creating a translation. So the radio buttons for allowLanguageSynchronization are set to 'custom value' by default.
<?php
namespace Some\Client\Hooks;
/**
* DataHandler
*
* Contains hooks for the \TYPO3\CMS\Core\DataHandling\DataHandler class
*/
class DataHandler
{
/**
* Populate l10n_state field of tt_content records when creating a translation. So the radio buttons for
* allowLanguageSynchronization are set to 'custom value' by default.
*
* @param \TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler
*/
public function processDatamap_beforeStart(\TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler): void
{
if (empty($dataHandler->datamap['tt_content'])) {
return;
}
foreach ($dataHandler->datamap['tt_content'] as $id => $record) {
if (strpos($id, 'NEW') === false) {
continue;
}
$l10n_state = '{"image": "custom"}';
if ($record['l10n_state']) {
$defaultState = json_decode($record['l10n_state'], true);
$defaultState['image'] = 'custom';
$l10n_state = json_encode($defaultState, JSON_FORCE_OBJECT);
}
$record['l10n_state'] = $l10n_state;
$dataHandler->datamap['tt_content'][$id] = $record;
}
}
}
@Tuurlijk
Copy link
Author

2022-01-21_16-35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment