flux icon indicating copy to clipboard operation
flux copied to clipboard

Copy translated pages, the grids remain empty

Open Zellwerker opened this issue 2 years ago • 3 comments

Hello,

Flux 9.7.2 TYPO3 11.5.x

copy translated freemode pages. In the copy, the grids remain empty because the colPos still refers to the original. It only happens in the translation of the pages, default language is copied correctly.

Correctly, they should have the new colPos, so the grids appear empty. But in fact the content elements are there (visible with list module).

The following code in the file EXT:flux/Classes/Integration/HookSubscribers/DataHandlerSubscriber.php fixes the problem. It is only tested with freemode pages.

// Change this // ===========================


    public function processCmdmap_postProcess(
        &$command,
        $table,
        $id,
        &$relativeTo,
        &$reference,
        &$pasteUpdate,
        &$pasteDataMap
    ) {

        /*
        if ($table === 'pages' && $command === 'copy') {
            foreach ($reference->copyMappingArray['tt_content'] ?? [] as $originalRecordUid => $copiedRecordUid) {
                $copiedRecord = $this->getSingleRecordWithoutRestrictions('tt_content', $copiedRecordUid, 'colPos');
                if ($copiedRecord['colPos'] < ColumnNumberUtility::MULTIPLIER) {
                    continue;
                }
                $oldParentUid = ColumnNumberUtility::calculateParentUid($copiedRecord['colPos']);
                $newParentUid = $reference->copyMappingArray['tt_content'][$oldParentUid];
                $overrideArray['colPos'] = ColumnNumberUtility::calculateColumnNumberForParentAndColumn(
                    $newParentUid,
                    ColumnNumberUtility::calculateLocalColumnNumber((int) $copiedRecord['colPos'])
                );
                // Note here: it is safe to directly update the DB in this case, since we filtered out any
                // non-"copy" actions, and "copy" is the only action which requires adjustment.
                $reference->updateDB('tt_content', $copiedRecordUid, $overrideArray);
                // But if we also have a workspace version of the record recorded, it too must be updated:
                if (isset($reference->autoVersionIdMap['tt_content'][$copiedRecordUid])) {
                    $reference->updateDB(
                        'tt_content',
                        $reference->autoVersionIdMap['tt_content'][$copiedRecordUid],
                        $overrideArray
                    );
                }
            }
        }
        */

// Into this // ===========================

    public function processCmdmap_postProcess(
        &$command,
        $table,
        $id,
        &$relativeTo,
        &$reference,
        &$pasteUpdate,
        &$pasteDataMap
    ) {

        if ($table === 'pages' && $command === 'copy') {
            foreach ($reference->copyMappingArray['tt_content'] ?? [] as $originalRecordUid => $copiedRecordUid) {
                $copiedRecord = $this->getSingleRecordWithoutRestrictions('tt_content', $copiedRecordUid, 'colPos');
                if ($copiedRecord['colPos'] < ColumnNumberUtility::MULTIPLIER) {
                    continue;
                }

                $originalRecord = $this->getSingleRecordWithoutRestrictions('tt_content', $originalRecordUid, 'colPos');

                $oldParentUid = ColumnNumberUtility::calculateParentUid($originalRecord['colPos']);
                $newParentUid = $reference->copyMappingArray['tt_content'][$oldParentUid];

                $overrideArray['colPos'] = ColumnNumberUtility::calculateColumnNumberForParentAndColumn(
                    $newParentUid,
                    ColumnNumberUtility::calculateLocalColumnNumber((int) $copiedRecord['colPos'])
                );

                // Note here: it is safe to directly update the DB in this case, since we filtered out any
                // non-"copy" actions, and "copy" is the only action which requires adjustment.
                $reference->updateDB('tt_content', $copiedRecordUid, $overrideArray);

                // But if we also have a workspace version of the record recorded, it too must be updated:
                if (isset($reference->autoVersionIdMap['tt_content'][$copiedRecordUid])) {
                    $reference->updateDB('tt_content', $reference->autoVersionIdMap['tt_content'][$copiedRecordUid], $overrideArray);
                }
            }
        }

Zellwerker avatar Feb 03 '23 10:02 Zellwerker

Hi @Zellwerker,

Just a quick note for now: this code block was deactivated because it caused problems with other copy operations. Unfortunately, TYPO3 chose to use the copy command instead of a unique command when triggering a "translate" operation in free mode. Last time I checked there was no way to distinguish a normal copy command from a copy command triggered by translating. This was quite some time ago though, so I'll leave the issue open as a reminder to check if there's a way today to only trigger this block in context of a "translate" action in free mode.

NamelessCoder avatar Feb 17 '23 13:02 NamelessCoder

Thank you for your feedback.

In my case it works with TYPO3 11.5.x. As already described, I have not tried it with connected mode and cannot say whether it has an effect in copied pages.

I am very interested to hear your results and hope that TYPO3 will provide better interfaces for such cases.

Zellwerker avatar Feb 17 '23 14:02 Zellwerker

There should be no negative effects in connected mode, since IIRC the command then changes to copyToLanguage which of course doesn't trigger this block. It's only free mode that causes a bit of a headache.

NamelessCoder avatar Feb 17 '23 14:02 NamelessCoder