Commit b7118cc9 authored by Oliver Hader's avatar Oliver Hader Committed by Oliver Hader
Browse files

[TASK] Avoid inline JavaScript in f:be.menus.actionMenu

Uses GlobalEventHandler functionality instead of onchange events.

Resolves: #96018
Releases: master, 11.5
Change-Id: Ib217b294b9f3d0ff27c005b0d4f397aa2bfd665c
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72221


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Torben Hansen's avatarTorben Hansen <derhansen@gmail.com>
Tested-by: Oliver Hader's avatarOliver Hader <oliver.hader@typo3.org>
Reviewed-by: Torben Hansen's avatarTorben Hansen <derhansen@gmail.com>
Reviewed-by: Oliver Hader's avatarOliver Hader <oliver.hader@typo3.org>
parent c8155922
......@@ -15,6 +15,9 @@
namespace TYPO3\CMS\Fluid\ViewHelpers\Be\Menus;
use TYPO3\CMS\Core\Page\JavaScriptModuleInstruction;
use TYPO3\CMS\Core\Page\JavaScriptRenderer;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler;
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
......@@ -80,15 +83,19 @@ class ActionMenuViewHelper extends AbstractTagBasedViewHelper
*/
public function render()
{
$this->tag->addAttribute('onchange', 'window.location.href = this.options[this.selectedIndex].value;');
$options = '';
foreach ($this->childNodes as $childNode) {
if ($childNode instanceof ViewHelperNode) {
$options .= $childNode->evaluate($this->renderingContext);
}
}
$this->tag->addAttributes([
'data-global-event' => 'change',
'data-action-navigate' => '$value',
]);
$this->tag->setContent($options);
return '<div class="docheader-funcmenu">' . $this->tag->render() . '</div>';
return $this->loadRequireJsModule('TYPO3/CMS/Backend/GlobalEventHandler')
. '<div class="docheader-funcmenu">' . $this->tag->render() . '</div>';
}
/**
......@@ -104,4 +111,18 @@ class ActionMenuViewHelper extends AbstractTagBasedViewHelper
$compiler->disable();
return null;
}
/**
* Renders `<script src="JavaScriptHandler.js">...</script>` for loading
* corresponding module. Using `JavaScriptRenderer` makes this independent
* from `PageRenderer` and its current application state.
*/
protected function loadRequireJsModule(string $name): string
{
$javaScriptRenderer = JavaScriptRenderer::create();
$javaScriptRenderer->addJavaScriptModuleInstruction(
JavaScriptModuleInstruction::forRequireJS($name)
);
return $javaScriptRenderer->render();
}
}
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