diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 83ae2bc..f563fbb 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 9525df3..cd062e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/composer.json b/composer.json index c101d69..acbd66c 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -51,7 +52,9 @@ "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": { diff --git a/os2forms_rest_api.info.yml b/os2forms_rest_api.info.yml index 06a73f5..b8a32a0 100644 --- a/os2forms_rest_api.info.yml +++ b/os2forms_rest_api.info.yml @@ -7,3 +7,4 @@ dependencies: - drupal:key_auth - drupal:webform - drupal:webform_rest + - os2forms:os2forms_attachment diff --git a/patches/webform_rest_submission.patch b/patches/webform_rest_submission.patch index 0ee1fc3..bb881e5 100644 --- a/patches/webform_rest_submission.patch +++ b/patches/webform_rest_submission.patch @@ -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; @@ -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. + * @@ -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); @@ -103,5 +103,5 @@ index d2e08c5..a9cacf7 100644 - 'data' => $data, + 'data' => $event->getData(), ]; - + // Return the submission. diff --git a/src/EventSubscriber/WebformSubmissionDataEventSubscriber.php b/src/EventSubscriber/WebformSubmissionDataEventSubscriber.php index 5b35d92..291602b 100644 --- a/src/EventSubscriber/WebformSubmissionDataEventSubscriber.php +++ b/src/EventSubscriber/WebformSubmissionDataEventSubscriber.php @@ -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; @@ -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;