getUser(); $route = null; $defaultReport = $user->getPreferenceValue('reporting.initial_view', ReportingService::DEFAULT_VIEW); $allReports = $reportingService->getAvailableReports($user); foreach ($allReports as $report) { if ($report->getId() === $defaultReport) { $route = $report->getRoute(); break; } } // fallback, if the configured report could not be found // eg. when it was deleted or replaced by an enhanced version with a new id if ($route === null && \count($allReports) > 0) { $report = $allReports[array_keys($allReports)[0]]; $route = $report->getRoute(); } if ($route === null) { throw $this->createNotFoundException('Unknown default report'); } return $this->redirectToRoute($route); } }