Skip to content

Commit

Permalink
[FEATURE] Improve localization of pages
Browse files Browse the repository at this point in the history
This patch implements two changes:

* Sets "allowLanguageSynchronization" behavior on page template fields.
* Copies values of "page configuration" fields when page is localized.

Close: FluidTYPO3#1910
  • Loading branch information
NamelessCoder committed Aug 5, 2023
1 parent fc5464f commit 29e8488
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Classes/Integration/HookSubscribers/DataHandlerSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use FluidTYPO3\Flux\Content\ContentTypeManager;
use FluidTYPO3\Flux\Provider\Interfaces\GridProviderInterface;
use FluidTYPO3\Flux\Provider\Interfaces\RecordProcessingProvider;
use FluidTYPO3\Flux\Provider\PageProvider;
use FluidTYPO3\Flux\Provider\ProviderResolver;
use FluidTYPO3\Flux\Utility\ColumnNumberUtility;
use TYPO3\CMS\Backend\Utility\BackendUtility;
Expand Down Expand Up @@ -169,6 +170,26 @@ public function processDatamap_afterDatabaseOperations($command, $table, $id, $f
// @phpcs:ignore PSR1.Methods.CamelCapsMethodName
public function processDatamap_preProcessFieldArray(array &$fieldArray, $table, $id, DataHandler $dataHandler)
{
if ($table === 'pages' && strpos((string) $id, 'NEW') === 0 && ($fieldArray['l10n_source'] ?? 0) > 0) {
// Record is a newly created page and is a translation of a page. In all likelyhood (but we can't actually
// know for sure since TYPO3 uses a nested DataHandler for this...) this record is the result of a blank
// initial copy of the original language's record. We may want to copy the "Page Configuration" fields'
// values from the original record.
if (!isset($fieldArray[PageProvider::FIELD_NAME_MAIN], $fieldArray[PageProvider::FIELD_NAME_SUB])) {
// To make completely sure, we only want to copy those values if both "Page Configuration" fields are
// completely omitted from the incoming field array.
$originalLanguageRecord = $this->getSingleRecordWithoutRestrictions(
'pages',
$fieldArray['l10n_source'],
PageProvider::FIELD_NAME_MAIN . ',' . PageProvider::FIELD_NAME_SUB
);
if ($originalLanguageRecord) {
$fieldArray[PageProvider::FIELD_NAME_MAIN] = $originalLanguageRecord[PageProvider::FIELD_NAME_MAIN];
$fieldArray[PageProvider::FIELD_NAME_SUB] = $originalLanguageRecord[PageProvider::FIELD_NAME_SUB];
}
}
}

// Handle "$table.$field" named fields where $table is the valid TCA table name and $field is an existing TCA
// field. Updated value will still be subject to permission checks.
$resolver = $this->getProviderResolver();
Expand Down
7 changes: 7 additions & 0 deletions Configuration/TCA/Overrides/pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'behaviour' => [
'allowLanguageSynchronization' => true,
],
'fieldWizard' => [
'selectIcons' => [
'disabled' => false
Expand All @@ -23,9 +26,13 @@
'exclude' => 1,
'label' => 'LLL:EXT:flux/Resources/Private/Language/locallang.xlf:pages.tx_fed_page_controller_action_sub',
'onChange' => 'reload',

'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'behaviour' => [
'allowLanguageSynchronization' => true,
],
'fieldWizard' => [
'selectIcons' => [
'disabled' => false
Expand Down

0 comments on commit 29e8488

Please sign in to comment.