Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy translated pages, the grids remain empty #2062

Open
Zellwerker opened this issue Feb 3, 2023 · 3 comments
Open

Copy translated pages, the grids remain empty #2062

Zellwerker opened this issue Feb 3, 2023 · 3 comments

Comments

@Zellwerker
Copy link

Zellwerker commented Feb 3, 2023

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);
                }
            }
        }
@NamelessCoder
Copy link
Member

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.

@Zellwerker
Copy link
Author

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.

@NamelessCoder
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants