From d04485911c8ab21d52dc00f732c04e8b1e5b199e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Rajchl?= Date: Mon, 5 Jan 2026 07:52:50 +0100 Subject: [PATCH] LinkGenerator: allow 'test' mode in link target validation The change allows the use/validation of 'test' mode over presenters containing the Requires attribute (e.g., using the isLinkCurrent method on the Error4xx presenter). --- src/Application/LinkGenerator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Application/LinkGenerator.php b/src/Application/LinkGenerator.php index 122fdfc7b..3c89ffea7 100644 --- a/src/Application/LinkGenerator.php +++ b/src/Application/LinkGenerator.php @@ -12,7 +12,7 @@ use Nette\Http\UrlScript; use Nette\Routing\Router; use Nette\Utils\Reflection; -use function array_intersect_key, array_key_exists, http_build_query, is_string, is_subclass_of, parse_str, preg_match, rtrim, str_contains, str_ends_with, strcasecmp, strlen, strncmp, strtr, substr, trigger_error, urldecode; +use function array_intersect_key, array_key_exists, http_build_query, in_array, is_string, is_subclass_of, parse_str, preg_match, rtrim, str_contains, str_ends_with, strcasecmp, strlen, strncmp, strtr, substr, trigger_error, urldecode; /** @@ -299,7 +299,7 @@ private function validateLinkTarget( string $mode, ): void { - if ($mode !== 'forward' && !(new UI\AccessPolicy($element))->isLinkable()) { + if (!in_array($mode, ['test', 'forward']) && !(new UI\AccessPolicy($element))->isLinkable()) { throw new UI\InvalidLinkException("Link to forbidden $message from '{$presenter->getName()}:{$presenter->getAction()}'."); } elseif ($presenter?->invalidLinkMode && (UI\ComponentReflection::parseAnnotation($element, 'deprecated') || $element->getAttributes(Attributes\Deprecated::class))