* do not traverse into invoice template subdirectories (#3735) * fix security open api definition * fix currency can be null, removed fluent interface * merged release 1.30.3 * allow to pre-fill timesheet metafields via URL * fix api description * added test accounts with simpler names and password * upgrade to Symfony 6.2 * removed FrameworkExtraBundle (by Sensio) and replaced with new native SF annotations * fixed symfony 6.2 deprecations * fixed #3768
76 lines
2.1 KiB
PHP
76 lines
2.1 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Kimai time-tracking app.
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace App\EventSubscriber;
|
|
|
|
use App\Entity\User;
|
|
use App\Event\ConfigureMainMenuEvent;
|
|
use App\Utils\MenuItemModel;
|
|
use Symfony\Bundle\SecurityBundle\Security;
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
|
|
|
final class MenuFavoritesSubscriber implements EventSubscriberInterface
|
|
{
|
|
public function __construct(private Security $security)
|
|
{
|
|
}
|
|
|
|
public static function getSubscribedEvents(): array
|
|
{
|
|
return [
|
|
ConfigureMainMenuEvent::class => ['onMainMenuConfigure', 90], // see MenuSubscriber
|
|
];
|
|
}
|
|
|
|
public function onMainMenuConfigure(ConfigureMainMenuEvent $menuEvent): void
|
|
{
|
|
/** @var User $user */
|
|
$user = $this->security->getUser();
|
|
if (null === $user) {
|
|
return;
|
|
}
|
|
|
|
$favMenu = $menuEvent->getMenu()->findChild('favorites');
|
|
if ($favMenu === null) {
|
|
return;
|
|
}
|
|
|
|
$userFavorites = $user->getPreferenceValue('favorite_routes');
|
|
if (!\is_string($userFavorites) || trim($userFavorites) === '') {
|
|
return;
|
|
}
|
|
|
|
$root = new MenuItemModel('', '');
|
|
$root->addChild($menuEvent->getMenu());
|
|
|
|
if ($menuEvent->getAppsMenu()->hasChildren()) {
|
|
$root->addChild($menuEvent->getAppsMenu());
|
|
}
|
|
if ($menuEvent->getAdminMenu()->hasChildren()) {
|
|
$root->addChild($menuEvent->getAdminMenu());
|
|
}
|
|
if ($menuEvent->getSystemMenu()->hasChildren()) {
|
|
$root->addChild($menuEvent->getSystemMenu());
|
|
}
|
|
|
|
$userFavorites = explode(',', $userFavorites);
|
|
foreach ($userFavorites as $fav) {
|
|
$tmp = $root->findChild($fav);
|
|
if ($tmp !== null && !$tmp->hasChildren()) {
|
|
$favMenu->addChild(clone $tmp);
|
|
}
|
|
}
|
|
|
|
if ($favMenu->hasChildren()) {
|
|
$favMenu->setExpanded(true);
|
|
$menuEvent->getTimesheetMenu()?->setExpanded(false);
|
|
}
|
|
}
|
|
}
|