Skip to content

Commit 4681c85

Browse files
committed
OS-110 refactoring, service injections
1 parent 23fa488 commit 4681c85

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

modules/os2forms_digital_signature/src/Controller/DigitalSignatureController.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Drupal\Component\Utility\Crypt;
66
use Drupal\Core\Controller\ControllerBase;
7+
use Drupal\Core\Entity\EntityStorageInterface;
78
use Drupal\Core\File\FileExists;
89
use Drupal\Core\File\FileSystemInterface;
910
use Drupal\Core\Site\Settings;
@@ -13,13 +14,21 @@
1314
use Psr\Log\LoggerInterface;
1415
use Symfony\Component\DependencyInjection\ContainerInterface;
1516
use Symfony\Component\HttpFoundation\RedirectResponse;
17+
use Symfony\Component\HttpFoundation\RequestStack;
1618
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1719

1820
/**
1921
* Digital Signature Controller.
2022
*/
2123
class DigitalSignatureController extends ControllerBase {
2224

25+
/**
26+
* File Storage.
27+
*
28+
* @var EntityStorageInterface
29+
*/
30+
protected EntityStorageInterface $fileStorage;
31+
2332
/**
2433
* Constructor.
2534
*/
@@ -28,7 +37,9 @@ public function __construct(
2837
private readonly Settings $settings,
2938
private readonly SigningService $signingService,
3039
private readonly FileSystemInterface $fileSystem,
40+
private readonly RequestStack $requestStack,
3141
) {
42+
$this->fileStorage = $this->entityTypeManager()->getStorage('file');
3243
}
3344

3445
/**
@@ -40,6 +51,7 @@ public static function create(ContainerInterface $container) {
4051
$container->get('settings'),
4152
$container->get('os2forms_digital_signature.signing_service'),
4253
$container->get('file_system'),
54+
$container->get('request_stack'),
4355
);
4456
}
4557

@@ -63,7 +75,7 @@ public static function create(ContainerInterface $container) {
6375
*/
6476
public function signCallback($uuid, $hash, $fid = NULL) {
6577
// Load the webform submission entity by UUID.
66-
$submissions = \Drupal::entityTypeManager()
78+
$submissions = $this->entityTypeManager()
6779
->getStorage('webform_submission')
6880
->loadByProperties(['uuid' => $uuid]);
6981

@@ -78,7 +90,9 @@ public function signCallback($uuid, $hash, $fid = NULL) {
7890
$webformId = $webformSubmission->getWebform()->id();
7991

8092
// Checking the action.
81-
$action = \Drupal::request()->query->get('action');
93+
$request = $this->requestStack->getCurrentRequest();
94+
95+
$action = $request->query->get('action');
8296
if ($action == 'cancel') {
8397
$cancelUrl = $webformSubmission->getWebform()->toUrl()->toString();
8498

@@ -95,7 +109,7 @@ public function signCallback($uuid, $hash, $fid = NULL) {
95109
throw new NotFoundHttpException();
96110
}
97111

98-
$signedFilename = \Drupal::request()->get('file');
112+
$signedFilename = $request->get('file');
99113
$signedFileContent = $this->signingService->download($signedFilename);
100114
if (!$signedFileContent) {
101115
$this->logger->warning('Missing file on remote server %file.', ['%file' => $signedFilename]);
@@ -128,7 +142,7 @@ public function signCallback($uuid, $hash, $fid = NULL) {
128142

129143
// If file existing, resave the file to update the size and etc.
130144
if ($fid) {
131-
File::load($fid)->save();
145+
$this->fileStorage->load($fid)?->save();
132146
}
133147
}
134148
catch (\Exception $e) {

0 commit comments

Comments
 (0)