44
55use Drupal \Component \Utility \Crypt ;
66use Drupal \Core \Controller \ControllerBase ;
7+ use Drupal \Core \Entity \EntityStorageInterface ;
78use Drupal \Core \File \FileExists ;
89use Drupal \Core \File \FileSystemInterface ;
910use Drupal \Core \Site \Settings ;
1314use Psr \Log \LoggerInterface ;
1415use Symfony \Component \DependencyInjection \ContainerInterface ;
1516use Symfony \Component \HttpFoundation \RedirectResponse ;
17+ use Symfony \Component \HttpFoundation \RequestStack ;
1618use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
1719
1820/**
1921 * Digital Signature Controller.
2022 */
2123class 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