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

Insert button not working in Typo3 11 #8

Closed
tomashavner opened this issue Oct 19, 2022 · 5 comments
Closed

Insert button not working in Typo3 11 #8

tomashavner opened this issue Oct 19, 2022 · 5 comments
Labels
bug Something isn't working hacktoberfest

Comments

@tomashavner
Copy link

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

@tomashavner tomashavner added the bug Something isn't working label Oct 19, 2022
@Kephson
Copy link
Owner

Kephson commented Oct 20, 2022

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

@tomashavner
Copy link
Author

Hi,

If you replace
OnReady.setSelectOptionFromExternalSource = setFormValueFromBrowseWin = function (elementId, tableUid) {
tableUid = tableUid.replace('tt_content_', '') * 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
Copy link
Owner

Kephson commented Oct 24, 2022

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
Copy link
Author

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
Copy link
Owner

Kephson commented Oct 25, 2022

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

@Kephson Kephson closed this as completed Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hacktoberfest
Projects
None yet
Development

No branches or pull requests

2 participants