Skip to content

Commit

Permalink
#340 fix submit for lower t3 versions
Browse files Browse the repository at this point in the history
  • Loading branch information
digedag committed Nov 26, 2023
1 parent a3a0f54 commit ce93725
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Classes/Backend/Form/ToolBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,9 @@ public function createSubmit($name, $value, $confirmMsg = '', $options = [])
'name' => $name,
'value' => $value,
];
if (!TYPO3::isTYPO121OrHigher()) {
$attributes['data-href'] = sprintf('javascript:%s', htmlspecialchars('document.forms[\'editform\'].submit()'));
}

if (strlen($confirmMsg)) {
$class .= ' t3js-modal-trigger';
Expand Down Expand Up @@ -1220,8 +1223,7 @@ public static function showMenu($pid, $name, $modName, $entries, $script = '', $
if (is_array($MENU[$name]) && 1 == count($MENU[$name])) {
$ret['menu'] = self::buildDummyMenu('SET['.$name.']', $MENU[$name]);
} else {
$funcMenu = 'getDropdownMenu';
$ret['menu'] = BackendUtility::$funcMenu(
$ret['menu'] = BackendUtility::getDropdownMenu(
$pid,
'SET['.$name.']',
$SETTINGS[$name],
Expand Down
21 changes: 20 additions & 1 deletion Classes/Backend/Template/Override/DocumentTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Sys25\RnBase\Utility\Files;
use Sys25\RnBase\Utility\Strings;
use Sys25\RnBase\Utility\T3General;
use Sys25\RnBase\Utility\TYPO3;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -46,7 +47,20 @@ class DocumentTemplate

public $divClass = false;

/** @deprecated use external js files */
public $JScode = '';
public $endOfPageJsBlock = '';
/**
* Similar to $JScode but for use as array with associative keys to prevent double inclusion of JS code. a <script> tag is automatically wrapped around.
*
* @var array
*/
public $JScodeArray = ['jumpToUrl' => '
function jumpToUrl(URL) {
window.location.href = URL;
return false;
}
'];

/**
* JavaScript files loaded for every page in the Backend.
Expand Down Expand Up @@ -272,7 +286,12 @@ public function insertStylesAndJS($content)
{
// Insert accumulated JS
$jscode = '';
$content = str_replace('<!--###POSTJSMARKER###-->', $jscode, $content);
// TODO: check lowest version
if (!TYPO3::isTYPO121OrHigher()) {
$jscode = $this->JScode.LF.GeneralUtility::wrapJS(implode(LF, $this->JScodeArray));
$content = str_replace('<!--###POSTJSMARKER###-->', $jscode, $content);

}

return $content;
}
Expand Down
60 changes: 60 additions & 0 deletions Resources/Public/JavaScript/Toolbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

define([], function(jQuery) {

const FormTool = {

init: function() {
const self = this;
// Alle reload Elemente suchen
const elems = document.querySelectorAll('[data-action-submit="$form"][data-global-event]');
elems.forEach(function(elem) {
var event = elem.getAttribute('data-global-event');
elem.addEventListener(event, function() {
// Alle hidden Submit-Buttons suchen und entfernen
// Das ist hier kein Problem, weil sofort der Reload erfolgt
const hiddens = document.querySelectorAll('input[type="hidden"].rnbase-modal-submit-btn')
hiddens.forEach(function(hidden){
if (hidden.form) {
hidden.form.removeChild(hidden);
}
})
});
});
const editForm = document.forms['editform'];

// const btns = document.querySelectorAll('button[type="submit"].rnbase-btn.t3js-modal-trigger, input[type="submit"].rnbase-btn.t3js-modal-trigger');
const btns = document.querySelectorAll('button[type="submit"].rnbase-btn, input[type="submit"].rnbase-btn');
btns.forEach(function(btn) {
btn.addEventListener('click', function(evt) {
const hiddenField = document.querySelector('input[type="hidden"].rnbase-modal-submit-btn');
if (btn.classList.contains('t3js-modal-trigger')) {
// Hole den Namen des Submit-Buttons
hiddenField.name = btn.getAttribute('name');
hiddenField.value = '1';
} else {
hiddenField.name = '_none';
}
})
});
if (editForm) {
// Das hidden-Feld wird den Namen des Submit-Buttons bei Modal-Dialogen schicken
var hiddenField = document.querySelector('input[type="hidden"].rnbase-modal-submit-btn');
if (!hiddenField) {
hiddenField = document.createElement('input');
hiddenField.type = 'hidden';
hiddenField.className = 'rnbase-modal-submit-btn';
hiddenField.name = '_none';

// Füge das hidden-Feld zum Formular hinzu
editForm.appendChild(hiddenField);
}
}

console.info('Toolbox loaded');
}
}

FormTool.init();
});


0 comments on commit ce93725

Please sign in to comment.