Skip to content

Commit

Permalink
Merge pull request #7 from OS2Forms/feature/446-handle-os2forms-attac…
Browse files Browse the repository at this point in the history
…hments

#446: Handle os2forms_attachment
  • Loading branch information
jekuaitk authored Jan 11, 2024
2 parents 32fa7c1 + 1989fcf commit 798b204
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ jobs:
composer --no-interaction --working-dir=drupal config repositories.drupal composer https://packages.drupal.org/8
composer --no-interaction --working-dir=drupal config --no-plugins allow-plugins.cweagans/composer-patches true
composer --no-interaction --working-dir=drupal config --no-plugins allow-plugins.zaporylie/composer-drupal-optimizations true
composer --no-interaction --working-dir=drupal config --no-plugins allow-plugins.simplesamlphp/composer-module-installer true
# @see https://getcomposer.org/doc/03-cli.md#modifying-extra-values
composer --no-interaction --working-dir=drupal config --no-plugins --json extra.enable-patching true
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ about writing changes to this log.

## [Unreleased]

## [2.0.2]

- Added `OS2Forms Attachment` to attachments data.

## [2.0.1]

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

- Release 1.0.0

[Unreleased]: https://github.com/OS2Forms/os2forms_rest_api/compare/2.0.1...HEAD
[Unreleased]: https://github.com/OS2Forms/os2forms_rest_api/compare/2.0.2...HEAD
[2.0.2]: https://github.com/OS2Forms/os2forms_rest_api/compare/2.0.1...2.0.2
[2.0.1]: https://github.com/OS2Forms/os2forms_rest_api/compare/2.0.0...2.0.1
[2.0.0]: https://github.com/OS2Forms/os2forms_rest_api/compare/1.1.0...2.0.0
[1.1.0]: https://github.com/OS2Forms/os2forms_rest_api/compare/1.0.0...1.1.0
Expand Down
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"require": {
"cweagans/composer-patches": "^1.7",
"drupal/key_auth": "^2.0",
"drupal/webform_rest": "^4.0"
"drupal/webform_rest": "^4.1",
"os2forms/os2forms": "^3.13"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.2",
Expand Down Expand Up @@ -51,14 +52,16 @@
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"cweagans/composer-patches": true
"cweagans/composer-patches": true,
"zaporylie/composer-drupal-optimizations": true,
"simplesamlphp/composer-module-installer": true
}
},
"extra": {
"enable-patching": true,
"patches": {
"drupal/webform_rest": {
"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"
"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"
}
}
}
Expand Down
1 change: 1 addition & 0 deletions os2forms_rest_api.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ dependencies:
- drupal:key_auth
- drupal:webform
- drupal:webform_rest
- os2forms:os2forms_attachment
24 changes: 12 additions & 12 deletions patches/webform_rest_submission.patch
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ index 0000000..c378f45
+ }
+}
diff --git a/src/Plugin/rest/resource/WebformSubmissionResource.php b/src/Plugin/rest/resource/WebformSubmissionResource.php
index d2e08c5..a9cacf7 100644
index ebe22aa..4102129 100644
--- a/src/Plugin/rest/resource/WebformSubmissionResource.php
+++ b/src/Plugin/rest/resource/WebformSubmissionResource.php
@@ -5,6 +5,7 @@ namespace Drupal\webform_rest\Plugin\rest\resource;
Expand All @@ -67,11 +67,11 @@ index d2e08c5..a9cacf7 100644
+use Drupal\webform_rest\Event\WebformSubmissionDataEvent;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -35,6 +36,13 @@ class WebformSubmissionResource extends ResourceBase {
*/
protected $request;

@@ -43,6 +44,13 @@ class WebformSubmissionResource extends ResourceBase {

protected $currentUser;

+ /**
+ * An event dispatcher instance to use for dispatching events.
+ *
Expand All @@ -82,18 +82,18 @@ index d2e08c5..a9cacf7 100644
/**
* {@inheritdoc}
*/
@@ -42,6 +50,7 @@ class WebformSubmissionResource extends ResourceBase {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
@@ -51,6 +59,7 @@ class WebformSubmissionResource extends ResourceBase {
$instance->entityTypeManager = $container->get('entity_type.manager');
$instance->request = $container->get('request_stack');
$instance->currentUser = $container->get('current_user');
+ $instance->eventDispatcher = $container->get('event_dispatcher');
return $instance;
}
@@ -91,9 +100,13 @@ class WebformSubmissionResource extends ResourceBase {

@@ -110,9 +119,13 @@ class WebformSubmissionResource extends ResourceBase {
// Grab submission data.
$data = $webform_submission->getData();

+ // Dispatch WebformSubmissionDataEvent to allow modification of data.
+ $event = new WebformSubmissionDataEvent($webform_submission, $data);
+ $this->eventDispatcher->dispatch($event);
Expand All @@ -103,5 +103,5 @@ index d2e08c5..a9cacf7 100644
- 'data' => $data,
+ 'data' => $event->getData(),
];

// Return the submission.
9 changes: 9 additions & 0 deletions src/EventSubscriber/WebformSubmissionDataEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\file\FileInterface;
use Drupal\os2forms_attachment\Element\AttachmentElement;
use Drupal\webform\WebformInterface;
use Drupal\webform\WebformSubmissionInterface;
use Drupal\webform_entity_print_attachment\Element\WebformEntityPrintAttachment;
Expand Down Expand Up @@ -146,6 +147,14 @@ private function buildAttachments(WebformSubmissionInterface $submission, array
'url' => $url->toString(TRUE)->getGeneratedUrl(),
];
}
elseif ('os2forms_attachment' === $element['#type']) {
$url = AttachmentElement::getFileUrl($element, $submission);
$attachments[$key] = [
'name' => $element['#title'] ?? $name,
'type' => $element['#export_type'] ?? '',
'url' => $url->toString(TRUE)->getGeneratedUrl(),
];
}
}

return $attachments;
Expand Down

0 comments on commit 798b204

Please sign in to comment.