Commit 849a22da authored by Andreas Fernandez's avatar Andreas Fernandez Committed by Daniel Goerz
Browse files

[TASK] Open LinkBrowser in modal window

The LinkBrowser used in FormEngine is now opened in a modal window
instead of a popup.

Resolves: #88471
Releases: master
Change-Id: I59992b2fc8a9fbf6b01aa2213c024fd0c13de009
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60860

Tested-by: Markus Klein's avatarMarkus Klein <markus.klein@typo3.org>
Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Markus Klein's avatarMarkus Klein <markus.klein@typo3.org>
Reviewed-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
parent 55f7beae
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
import * as $ from 'jquery';
import FormEngine = require('TYPO3/CMS/Backend/FormEngine');
import Modal = require('../../Modal');
/**
* This module is used for the field control "Link popup"
*/
class LinkPopup {
private controlElement: HTMLElement = null;
constructor(controlElementId: string) {
$((): void => {
this.controlElement = <HTMLElement>document.querySelector(controlElementId);
this.controlElement.addEventListener('click', this.handleControlClick);
});
}
/**
* @param {Event} e
*/
private handleControlClick = (e: Event): void => {
e.preventDefault();
const itemName = this.controlElement.dataset.itemName;
const url = this.controlElement.getAttribute('href')
+ '&P[currentValue]=' + encodeURIComponent(document.editform[itemName].value)
+ '&P[currentSelectedValues]=' + encodeURIComponent(FormEngine.getFieldElement(itemName).val());
Modal.advanced({
type: Modal.types.iframe,
content: url,
size: Modal.sizes.large,
});
}
}
export = LinkPopup;
......@@ -66,7 +66,7 @@ class LinkBrowserController extends AbstractLinkBrowserController
unset($this->parameters['fieldChangeFunc']['alert']);
$update = [];
foreach ($this->parameters['fieldChangeFunc'] as $v) {
$update[] = 'parent.opener.' . $v;
$update[] = 'FormEngineLinkBrowserAdapter.getParent().' . $v;
}
$inlineJS = implode(LF, $update);
......
......@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Backend\Form\FieldControl;
use TYPO3\CMS\Backend\Form\AbstractNode;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
/**
* Renders the icon with link parameters to open the element browser.
......@@ -37,7 +38,6 @@ class LinkPopup extends AbstractNode
$parameterArray = $this->data['parameterArray'];
$itemName = $parameterArray['itemFormElName'];
$windowOpenParameters = $options['windowOpenParameters'] ?? 'height=800,width=1000,status=0,menubar=0,scrollbars=1';
$linkBrowserArguments = [];
if (isset($options['blindLinkOptions'])) {
......@@ -66,27 +66,19 @@ class LinkPopup extends AbstractNode
/** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
$uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
$url = (string)$uriBuilder->buildUriFromRoute('wizard_link', $urlParameters);
$onClick = [];
$onClick[] = 'this.blur();';
$onClick[] = 'vHWin=window.open(';
$onClick[] = GeneralUtility::quoteJSvalue($url);
$onClick[] = '+\'&P[currentValue]=\'+TBE_EDITOR.rawurlencode(';
$onClick[] = 'document.editform[' . GeneralUtility::quoteJSvalue($itemName) . '].value';
$onClick[] = ')';
$onClick[] = '+\'&P[currentSelectedValues]=\'+TBE_EDITOR.curSelected(';
$onClick[] = GeneralUtility::quoteJSvalue($itemName);
$onClick[] = '),';
$onClick[] = '\'\',';
$onClick[] = GeneralUtility::quoteJSvalue($windowOpenParameters);
$onClick[] = ');';
$onClick[] = 'vHWin.focus();';
$onClick[] = 'return false;';
$id = StringUtility::getUniqueId('t3js-formengine-fieldcontrol-');
return [
'iconIdentifier' => 'actions-wizard-link',
'title' => $title,
'linkAttributes' => [
'onClick' => implode('', $onClick),
'id' => htmlspecialchars($id),
'href' => $url,
'data-item-name' => htmlspecialchars($itemName),
],
'requireJsModules' => [
['TYPO3/CMS/Backend/FormEngine/FieldControl/LinkPopup' => 'function(LinkPopup) {new LinkPopup(' . GeneralUtility::quoteJSvalue('#' . $id) . ');}'],
],
];
}
......
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
define(["require","exports","jquery","TYPO3/CMS/Backend/FormEngine","../../Modal"],function(e,t,n,o,l){"use strict";return function(e){var t=this;this.controlElement=null,this.handleControlClick=function(e){e.preventDefault();var n=t.controlElement.dataset.itemName,r=t.controlElement.getAttribute("href")+"&P[currentValue]="+encodeURIComponent(document.editform[n].value)+"&P[currentSelectedValues]="+encodeURIComponent(o.getFieldElement(n).val());l.advanced({type:l.types.iframe,content:r,size:l.sizes.large})},n(function(){t.controlElement=document.querySelector(e),t.controlElement.addEventListener("click",t.handleControlClick)})}});
\ No newline at end of file
......@@ -15,7 +15,7 @@
* Module: TYPO3/CMS/Backend/FormEngineLinkBrowserAdapter
* LinkBrowser communication with parent window
*/
define(['jquery', 'TYPO3/CMS/Recordlist/LinkBrowser'], function($, LinkBrowser) {
define(['jquery', 'TYPO3/CMS/Recordlist/LinkBrowser', 'TYPO3/CMS/Backend/Modal'], function($, LinkBrowser, Modal) {
'use strict';
/**
......@@ -34,10 +34,12 @@ define(['jquery', 'TYPO3/CMS/Recordlist/LinkBrowser'], function($, LinkBrowser)
*/
FormEngineLinkBrowserAdapter.checkReference = function() {
var selector = 'form[name="' + LinkBrowser.parameters.formName + '"] [data-formengine-input-name="' + LinkBrowser.parameters.itemName + '"]';
if (window.opener && window.opener.document && window.opener.document.querySelector(selector)) {
return window.opener.document.querySelector(selector);
let opener = FormEngineLinkBrowserAdapter.getParent();
if (opener && opener.document && opener.document.querySelector(selector)) {
return opener.document.querySelector(selector);
} else {
close();
Modal.dismiss();
}
};
......@@ -59,18 +61,52 @@ define(['jquery', 'TYPO3/CMS/Recordlist/LinkBrowser'], function($, LinkBrowser)
method: 'GET'
}).done(function(data) {
if (data.typoLink) {
$('#' + field.id, parent.opener.document).val(data.typoLink);
let opener = FormEngineLinkBrowserAdapter.getParent();
$('#' + field.id, opener.document).val(data.typoLink);
if (typeof field.onchange === 'function') {
field.onchange();
}
FormEngineLinkBrowserAdapter.updateFunctions();
if (typeof FormEngineLinkBrowserAdapter.updateFunctions === 'function') {
FormEngineLinkBrowserAdapter.updateFunctions();
}
close();
Modal.dismiss();
}
});
}
};
/**
* Returns the parent document object
*/
FormEngineLinkBrowserAdapter.getParent = function() {
let opener;
if (
typeof window.parent !== 'undefined' &&
typeof window.parent.document.list_frame !== 'undefined' &&
window.parent.document.list_frame.parent.document.querySelector('.t3js-modal-iframe') !== null
) {
opener = window.parent.document.list_frame;
} else if (
typeof window.parent !== 'undefined' &&
typeof window.parent.frames.list_frame !== 'undefined' &&
window.parent.frames.list_frame.parent.document.querySelector('.t3js-modal-iframe') !== null
) {
opener = window.parent.frames.list_frame;
} else if (
typeof window.frames !== 'undefined' &&
typeof window.frames.frameElement !== 'undefined' &&
window.frames.frameElement !== null &&
window.frames.frameElement.classList.contains('t3js-modal-iframe')
) {
opener = window.frames.frameElement.contentWindow.parent;
} else if (window.opener) {
opener = window.opener;
}
return opener;
};
return FormEngineLinkBrowserAdapter;
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment