Undo the double-escaped module descriptions in the backend menu tooltips

Contao escapes the descriptions in BackendUser::navigation() and the menu
template escapes the title attribute again, so "W&K" showed as "W&K".

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Jürgen MummertandClaude Fable 5.1 committed 2026-09-26 16:29:14 +02:00
1 parent 59bb6322a0
commit 007b5b1d80
1 file changed
+35
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace Mummert\ContaoWkSyncBundle\EventListener\Menu;
use Contao\CoreBundle\Event\MenuEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
/**
* Contao escaped die Modul-Beschreibungen für den Tooltip der Backend-Navigation bereits in
* BackendUser::navigation() (StringUtil::specialchars) und das Menü-Template escaped das
* title-Attribut ein zweites Mal, sodass aus „W&K“ im Tooltip „W&amp;K“ wird. Der Core-Listener
* läuft mit Priorität 10; dieser Listener nimmt die erste Escapierung für die W&K-Module zurück.
*/
#[AsEventListener]
class BackendMenuTitleListener
{
public function __invoke(MenuEvent $event): void
{
$tree = $event->getTree();
if ('mainMenu' !== $tree->getName() || null === ($group = $tree->getChild('wk_tools'))) {
return;
}
foreach ($group->getChildren() as $item) {
$title = $item->getLinkAttribute('title');
if (\is_string($title) && str_contains($title, '&')) {
$item->setLinkAttribute('title', html_entity_decode($title, ENT_QUOTES | ENT_HTML5, 'UTF-8'));
}
}
}
}