From 376eb221fe14c244a527501fd466f9fd992fe9f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Anne?= Date: Wed, 15 Jan 2025 10:29:36 +0100 Subject: [PATCH] Fix missing URLs prefixes * Fix fuzzy search URLs prefix * Fix sublist URL prefix --- .phpstan-baseline.php | 6 ------ src/Html.php | 12 ++++++------ templates/components/form/viewsubitem.html.twig | 2 +- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/.phpstan-baseline.php b/.phpstan-baseline.php index e1924d984aa..29901ddc2a9 100644 --- a/.phpstan-baseline.php +++ b/.phpstan-baseline.php @@ -3541,12 +3541,6 @@ 'count' => 1, 'path' => __DIR__ . '/src/Html.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method Html\\:\\:getMenuFuzzySearchList\\(\\) should return array\\{url\\: string, title\\: string\\} but returns list\\\\.$#', - 'identifier' => 'return.type', - 'count' => 1, - 'path' => __DIR__ . '/src/Html.php', -]; $ignoreErrors[] = [ 'message' => '#^Negated boolean expression is always true\\.$#', 'identifier' => 'booleanNot.alwaysTrue', diff --git a/src/Html.php b/src/Html.php index 688697afe36..f29e39519e4 100644 --- a/src/Html.php +++ b/src/Html.php @@ -6093,7 +6093,7 @@ private static function getMiniFile($file_path) * * @return string */ - final public static function getPrefixedUrl($url) + final public static function getPrefixedUrl(string $url): string { /** @var array $CFG_GLPI */ global $CFG_GLPI; @@ -6139,7 +6139,7 @@ public static function manageRefreshPage($timer = false, $callback = null) /** * Get all options for the menu fuzzy search * @return array - * @phpstan-return array{url: string, title: string} + * @phpstan-return array * @since 11.0.0 */ public static function getMenuFuzzySearchList(): array @@ -6151,7 +6151,7 @@ public static function getMenuFuzzySearchList(): array if (isset($firstlvl['default'])) { if (strlen($firstlvl['title']) > 0) { $fuzzy_entries[] = [ - 'url' => $firstlvl['default'], + 'url' => self::getPrefixedUrl($firstlvl['default']), 'title' => $firstlvl['title'] ]; } @@ -6160,7 +6160,7 @@ public static function getMenuFuzzySearchList(): array if (isset($firstlvl['default_dashboard'])) { if (strlen($firstlvl['title']) > 0) { $fuzzy_entries[] = [ - 'url' => $firstlvl['default_dashboard'], + 'url' => self::getPrefixedUrl($firstlvl['default_dashboard']), 'title' => $firstlvl['title'] . " > " . __('Dashboard') ]; } @@ -6170,7 +6170,7 @@ public static function getMenuFuzzySearchList(): array foreach ($firstlvl['content'] as $menu) { if (isset($menu['title']) && strlen($menu['title']) > 0) { $fuzzy_entries[] = [ - 'url' => $menu['page'], + 'url' => self::getPrefixedUrl($menu['page']), 'title' => $firstlvl['title'] . " > " . $menu['title'] ]; @@ -6178,7 +6178,7 @@ public static function getMenuFuzzySearchList(): array foreach ($menu['options'] as $submenu) { if (isset($submenu['title']) && strlen($submenu['title']) > 0) { $fuzzy_entries[] = [ - 'url' => $submenu['page'], + 'url' => self::getPrefixedUrl($submenu['page']), 'title' => $firstlvl['title'] . " > " . $menu['title'] . " > " . $submenu['title'] diff --git a/templates/components/form/viewsubitem.html.twig b/templates/components/form/viewsubitem.html.twig index 45d981fee3c..5e4bbd46968 100644 --- a/templates/components/form/viewsubitem.html.twig +++ b/templates/components/form/viewsubitem.html.twig @@ -62,7 +62,7 @@ modal_el[0].addEventListener('hidden.bs.modal', (event) => { event.target.removeAttribute('data-cy-ready'); }); - $('#{{ subitem_container_id }}').load('/ajax/viewsubitem.php',{ + $('#{{ subitem_container_id }}').load('{{ path('/ajax/viewsubitem.php')|e('js') }}',{ type: "{{ type|e('js') }}", parenttype: "{{ parenttype|e('js') }}", {{ items_id }}: {{ id }},