Kephson / paste_reference

Paste reference instead of copy for content elements in TYPO3
MIT License
14 stars 20 forks source link

Insert button not working in Typo3 11 #8

Closed tomashavner closed 1 year ago

tomashavner commented 1 year ago

Summary / Description

In Typo3 11, when you click the insert button (button with arrow) in page view and choose a content element, nothing happens.

Version

2.0.1

Steps to reproduce

In Typo3 11, when you click the insert button (button with arrow) in page view and choose a content element, nothing happens.

Expected behaviour

Dialog to copy or insert reference.

Actual behavior

Nothing happens.

Additional

Possible fix

paste_reference/Resources/Public/JavaScript/PasteReferenceOnReady.js line 145 ff uses setFormValueFromBrowseWin, which does not exist in Typo3 11. Replace with: require(['TYPO3/CMS/Backend/Utility/MessageUtility'], function (MessageUtility) { window.addEventListener('message', function (e) { etc

Miscellaneous

Kephson commented 1 year ago

Hi @tomashavner thanks for reporting; I will check it and release a new version if I could fix it.

tomashavner commented 1 year ago

Hi,

If you replace OnReady.setSelectOptionFromExternalSource = setFormValueFromBrowseWin = function (elementId, tableUid) { tableUid = tableUid.replace('ttcontent', '') * 1; DragDrop.default.onDrop(tableUid, $('#' + elementId).find('.t3js-paste-new'), 'copyFromAnotherPage'); } with: require(['TYPO3/CMS/Backend/Utility/MessageUtility'], function (MessageUtility) { window.addEventListener('message', function (e) {

        if (!MessageUtility.MessageUtility.verifyOrigin(e.origin)) {
            throw 'Denied message sent by ' + e.origin;
        }

        if (typeof e.data.fieldName === 'undefined') {
            throw 'fieldName not defined in message';
        }

        if (typeof e.data.value === 'undefined') {
            throw 'value not defined in message';
        }

        const result = e.data.value;
        var tableUid = result.replace('tt_content_', '') * 1;
        var elementId = e.data.fieldName;
        DragDrop.default.onDrop(tableUid, $('#' + elementId).find('.t3js-paste-new'), 'copyFromAnotherPage');
    });
});

paste_reference/Resources/Public/JavaScript/PasteReferenceOnReady.js will work. BUT there is a bug in paste_reference/Resources/Public/JavaScript/PasteReferenceDragDrop.js as well: You have to replace line 169: var $pasteElement = typeof Paste.itemOnClipboardUid === 'number' ? Paste.itemOnClipboardUid : $draggableElement; with: var $pasteElement = $draggableElement; if(typeof Paste.itemOnClipboardUid === 'number' && Paste.itemOnClipboardUid > 0) { $pasteElement = Paste.itemOnClipboardUid; } the reason is that 0 also is a number.

Kind regards

Tomas

Kephson commented 1 year ago

Hi thanks, I checked your changes, but there is still a problem: If you want to insert content from another page (and having elements in clipboard) it will always insert content from the clipboard and not the selected element. I'm trying to find the problem. Please check latest main commit.

tomashavner commented 1 year ago

Hi, Replace var $pasteElement = $draggableElement; if(typeof Paste.itemOnClipboardUid === 'number' && Paste.itemOnClipboardUid > 0) { $pasteElement = Paste.itemOnClipboardUid; } with if($draggableElement) { var $pasteElement = $draggableElement; } else if(typeof Paste.itemOnClipboardUid === 'number') { var $pasteElement = Paste.itemOnClipboardUid; }

Kephson commented 1 year ago

Thanks, I updated the script and tested it successfull. Released new version 2.0.2 of the extension.