Skip to content

Commit 4a438e0

Browse files
committed
Added dependency injection
1 parent 1b27d0d commit 4a438e0

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

os2forms_rest_api.services.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ services:
44
- '@entity_type.manager'
55
- '@current_user'
66
- '@key_auth.authentication.key_auth'
7+
- '@request_stack'
78

89
Drupal\os2forms_rest_api\EventSubscriber\EventSubscriber:
910
arguments:

src/WebformHelper.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Drupal\key_auth\Authentication\Provider\KeyAuth;
1111
use Drupal\webform\WebformInterface;
1212
use Drupal\webform\WebformSubmissionInterface;
13+
use Symfony\Component\HttpFoundation\RequestStack;
1314

1415
/**
1516
* Webform helper for helping with webforms.
@@ -38,13 +39,21 @@ class WebformHelper {
3839
*/
3940
private KeyAuth $keyAuth;
4041

42+
/**
43+
* The request stack.
44+
*
45+
* @var \Symfony\Component\HttpFoundation\RequestStack
46+
*/
47+
private RequestStack $requestStack;
48+
4149
/**
4250
* Constructor.
4351
*/
44-
public function __construct(EntityTypeManagerInterface $entityTypeManager, AccountProxyInterface $currentUser, KeyAuth $keyAuth) {
52+
public function __construct(EntityTypeManagerInterface $entityTypeManager, AccountProxyInterface $currentUser, KeyAuth $keyAuth, RequestStack $requestStack) {
4553
$this->entityTypeManager = $entityTypeManager;
4654
$this->currentUser = $currentUser;
4755
$this->keyAuth = $keyAuth;
56+
$this->requestStack = $requestStack;
4857
}
4958

5059
/**
@@ -244,7 +253,7 @@ private function loadUsers(array $spec): array {
244253
* @phpstan-return int|array<string, string>|null
245254
*/
246255
public function fileDownload(string $uri) {
247-
$request = \Drupal::request();
256+
$request = $this->requestStack->getCurrentRequest();
248257

249258
if ($user = $this->keyAuth->authenticate($request)) {
250259
// Find webform id from uri, see example uri.

0 commit comments

Comments
 (0)