Skip to content

Commit 798b204

Browse files
authored
Merge pull request #7 from OS2Forms/feature/446-handle-os2forms-attachments
#446: Handle os2forms_attachment
2 parents 32fa7c1 + 1989fcf commit 798b204

File tree

6 files changed

+37
-16
lines changed

6 files changed

+37
-16
lines changed

.github/workflows/pr.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ jobs:
123123
composer --no-interaction --working-dir=drupal config repositories.drupal composer https://packages.drupal.org/8
124124
125125
composer --no-interaction --working-dir=drupal config --no-plugins allow-plugins.cweagans/composer-patches true
126+
composer --no-interaction --working-dir=drupal config --no-plugins allow-plugins.zaporylie/composer-drupal-optimizations true
127+
composer --no-interaction --working-dir=drupal config --no-plugins allow-plugins.simplesamlphp/composer-module-installer true
128+
126129
# @see https://getcomposer.org/doc/03-cli.md#modifying-extra-values
127130
composer --no-interaction --working-dir=drupal config --no-plugins --json extra.enable-patching true
128131

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ about writing changes to this log.
88

99
## [Unreleased]
1010

11+
## [2.0.2]
12+
13+
- Added `OS2Forms Attachment` to attachments data.
14+
1115
## [2.0.1]
1216

1317
- Updated module config with new list submissions endpoint
@@ -28,7 +32,8 @@ about writing changes to this log.
2832

2933
- Release 1.0.0
3034

31-
[Unreleased]: https://github.com/OS2Forms/os2forms_rest_api/compare/2.0.1...HEAD
35+
[Unreleased]: https://github.com/OS2Forms/os2forms_rest_api/compare/2.0.2...HEAD
36+
[2.0.2]: https://github.com/OS2Forms/os2forms_rest_api/compare/2.0.1...2.0.2
3237
[2.0.1]: https://github.com/OS2Forms/os2forms_rest_api/compare/2.0.0...2.0.1
3338
[2.0.0]: https://github.com/OS2Forms/os2forms_rest_api/compare/1.1.0...2.0.0
3439
[1.1.0]: https://github.com/OS2Forms/os2forms_rest_api/compare/1.0.0...1.1.0

composer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"require": {
2121
"cweagans/composer-patches": "^1.7",
2222
"drupal/key_auth": "^2.0",
23-
"drupal/webform_rest": "^4.0"
23+
"drupal/webform_rest": "^4.1",
24+
"os2forms/os2forms": "^3.13"
2425
},
2526
"require-dev": {
2627
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.2",
@@ -51,14 +52,16 @@
5152
"sort-packages": true,
5253
"allow-plugins": {
5354
"dealerdirect/phpcodesniffer-composer-installer": true,
54-
"cweagans/composer-patches": true
55+
"cweagans/composer-patches": true,
56+
"zaporylie/composer-drupal-optimizations": true,
57+
"simplesamlphp/composer-module-installer": true
5558
}
5659
},
5760
"extra": {
5861
"enable-patching": true,
5962
"patches": {
6063
"drupal/webform_rest": {
61-
"Added ability to modify response data sent from Webform Submission endpoint": "https://raw.githubusercontent.com/OS2Forms/os2forms_rest_api/1.1.0/patches/webform_rest_submission.patch"
64+
"Added ability to modify response data sent from Webform Submission endpoint": "https://raw.githubusercontent.com/OS2Forms/os2forms_rest_api/2.0.2/patches/webform_rest_submission.patch"
6265
}
6366
}
6467
}

os2forms_rest_api.info.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ dependencies:
77
- drupal:key_auth
88
- drupal:webform
99
- drupal:webform_rest
10+
- os2forms:os2forms_attachment

patches/webform_rest_submission.patch

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ index 0000000..c378f45
5757
+ }
5858
+}
5959
diff --git a/src/Plugin/rest/resource/WebformSubmissionResource.php b/src/Plugin/rest/resource/WebformSubmissionResource.php
60-
index d2e08c5..a9cacf7 100644
60+
index ebe22aa..4102129 100644
6161
--- a/src/Plugin/rest/resource/WebformSubmissionResource.php
6262
+++ b/src/Plugin/rest/resource/WebformSubmissionResource.php
6363
@@ -5,6 +5,7 @@ namespace Drupal\webform_rest\Plugin\rest\resource;
@@ -67,11 +67,11 @@ index d2e08c5..a9cacf7 100644
6767
+use Drupal\webform_rest\Event\WebformSubmissionDataEvent;
6868
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
6969
use Symfony\Component\DependencyInjection\ContainerInterface;
70-
71-
@@ -35,6 +36,13 @@ class WebformSubmissionResource extends ResourceBase {
72-
*/
73-
protected $request;
74-
70+
71+
@@ -43,6 +44,13 @@ class WebformSubmissionResource extends ResourceBase {
72+
73+
protected $currentUser;
74+
7575
+ /**
7676
+ * An event dispatcher instance to use for dispatching events.
7777
+ *
@@ -82,18 +82,18 @@ index d2e08c5..a9cacf7 100644
8282
/**
8383
* {@inheritdoc}
8484
*/
85-
@@ -42,6 +50,7 @@ class WebformSubmissionResource extends ResourceBase {
86-
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
85+
@@ -51,6 +59,7 @@ class WebformSubmissionResource extends ResourceBase {
8786
$instance->entityTypeManager = $container->get('entity_type.manager');
8887
$instance->request = $container->get('request_stack');
88+
$instance->currentUser = $container->get('current_user');
8989
+ $instance->eventDispatcher = $container->get('event_dispatcher');
9090
return $instance;
9191
}
92-
93-
@@ -91,9 +100,13 @@ class WebformSubmissionResource extends ResourceBase {
92+
93+
@@ -110,9 +119,13 @@ class WebformSubmissionResource extends ResourceBase {
9494
// Grab submission data.
9595
$data = $webform_submission->getData();
96-
96+
9797
+ // Dispatch WebformSubmissionDataEvent to allow modification of data.
9898
+ $event = new WebformSubmissionDataEvent($webform_submission, $data);
9999
+ $this->eventDispatcher->dispatch($event);
@@ -103,5 +103,5 @@ index d2e08c5..a9cacf7 100644
103103
- 'data' => $data,
104104
+ 'data' => $event->getData(),
105105
];
106-
106+
107107
// Return the submission.

src/EventSubscriber/WebformSubmissionDataEventSubscriber.php

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

55
use Drupal\Core\Entity\EntityTypeManagerInterface;
66
use Drupal\file\FileInterface;
7+
use Drupal\os2forms_attachment\Element\AttachmentElement;
78
use Drupal\webform\WebformInterface;
89
use Drupal\webform\WebformSubmissionInterface;
910
use Drupal\webform_entity_print_attachment\Element\WebformEntityPrintAttachment;
@@ -146,6 +147,14 @@ private function buildAttachments(WebformSubmissionInterface $submission, array
146147
'url' => $url->toString(TRUE)->getGeneratedUrl(),
147148
];
148149
}
150+
elseif ('os2forms_attachment' === $element['#type']) {
151+
$url = AttachmentElement::getFileUrl($element, $submission);
152+
$attachments[$key] = [
153+
'name' => $element['#title'] ?? $name,
154+
'type' => $element['#export_type'] ?? '',
155+
'url' => $url->toString(TRUE)->getGeneratedUrl(),
156+
];
157+
}
149158
}
150159

151160
return $attachments;

0 commit comments

Comments
 (0)