Skip to content

Commit fe52fb0

Browse files
committed
Merge branch '5.2' into 5.x
* 5.2: [Workflow] Re-add InvalidTokenConfigurationException for BC Fix PHP 8.1 null values [Console] Fix PHP 8.1 null error for preg_match flag Fix: Article Definition::removeMethodCall should remove all matching calls [HttpFoundation] Fix typo in exception message mark the LazyIterator class as internal fix extracting mixed type-hinted property types [Worflow] Fixed GuardListener when using the new Security system keep valid submitted choices when additional choices are submitted
2 parents 798fe05 + c309827 commit fe52fb0

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

EventListener/GuardListener.php

+13-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
1818
use Symfony\Component\Validator\Validator\ValidatorInterface;
1919
use Symfony\Component\Workflow\Event\GuardEvent;
20-
use Symfony\Component\Workflow\Exception\InvalidTokenConfigurationException;
2120
use Symfony\Component\Workflow\TransitionBlocker;
2221

2322
/**
@@ -76,15 +75,8 @@ private function getVariables(GuardEvent $event): array
7675
{
7776
$token = $this->tokenStorage->getToken();
7877

79-
if (null === $token) {
80-
throw new InvalidTokenConfigurationException(sprintf('There are no tokens available for workflow "%s".', $event->getWorkflowName()));
81-
}
82-
8378
$variables = [
84-
'token' => $token,
85-
'user' => $token->getUser(),
8679
'subject' => $event->getSubject(),
87-
'role_names' => $this->roleHierarchy->getReachableRoleNames($token->getRoleNames()),
8880
// needed for the is_granted expression function
8981
'auth_checker' => $this->authorizationChecker,
9082
// needed for the is_* expression function
@@ -93,6 +85,18 @@ private function getVariables(GuardEvent $event): array
9385
'validator' => $this->validator,
9486
];
9587

96-
return $variables;
88+
if (null === $token) {
89+
return $variables + [
90+
'token' => null,
91+
'user' => null,
92+
'role_names' => [],
93+
];
94+
}
95+
96+
return $variables + [
97+
'token' => $token,
98+
'user' => $token->getUser(),
99+
'role_names' => $this->roleHierarchy->getReachableRoleNames($token->getRoleNames()),
100+
];
97101
}
98102
}

0 commit comments

Comments
 (0)