-
Notifications
You must be signed in to change notification settings - Fork 28
Open
Labels
Description
Summary / Description
If you create a new empty page, you can't paste elements on the page.
Version
TYPO3 13
PHP 8.3
Steps to reproduce
Create a new page. Then copy an element from another page and try to paste it on the new page.
Actual behavior
You get a JS error in the browser console:
paste-reference.js?bust=96ac5a2575ad9df067151bda05458c089fbebc23:199 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'parentElement')
at paste-reference.js?bust=96ac5a2575ad9df067151bda05458c089fbebc23:199:46
at NodeList.forEach (<anonymous>)
at Paste.activatePasteIcons (paste-reference.js?bust=96ac5a2575ad9df067151bda05458c089fbebc23:175:17)
at paste-reference.js?bust=96ac5a2575ad9df067151bda05458c089fbebc23:260:9
Additional
Possible fix
You need to fix the code from line 198 on.
Current code:
if (index === 0 && !element.parentElement.id) {
let tmpId = allElements[index + 1].parentElement.id;
let regex = /tt_content-[0-9]+/;
let id = tmpId.replace(regex, 'tt_content-0');
element.parentElement.setAttribute('id', id);
}
This is our quickfix:
if (index === 0 && (!element.parentElement || !element.parentElement.id)) {
let tmpId = allElements[index + 1]?.parentElement?.id || 'tt_content-0';
let regex = /tt_content-[0-9]+/;
let id = tmpId.replace(regex, 'tt_content-0');
element.parentElement.setAttribute('id', id);
} else {
element.setAttribute('id', id); // Assign to element if no parent exists
}