Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#446: Handle os2forms_attachment #7

Merged
merged 4 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Comment on lines +126 to +128
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# @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 @@ -49,16 +50,16 @@
/**
* Event handler.
*/
public function onWebformSubmissionDataEvent(WebformSubmissionDataEvent $event): void {

Check failure on line 53 in src/EventSubscriber/WebformSubmissionDataEventSubscriber.php

View workflow job for this annotation

GitHub Actions / PHP - Code analysis (8.1, prefer-lowest)

Parameter $event of method Drupal\os2forms_rest_api\EventSubscriber\WebformSubmissionDataEventSubscriber::onWebformSubmissionDataEvent() has invalid type Drupal\webform_rest\Event\WebformSubmissionDataEvent.

Check failure on line 53 in src/EventSubscriber/WebformSubmissionDataEventSubscriber.php

View workflow job for this annotation

GitHub Actions / PHP - Code analysis (8.1, prefer-stable)

Parameter $event of method Drupal\os2forms_rest_api\EventSubscriber\WebformSubmissionDataEventSubscriber::onWebformSubmissionDataEvent() has invalid type Drupal\webform_rest\Event\WebformSubmissionDataEvent.
$linkedData = $this->buildLinked($event->getWebformSubmission()->getWebform(), $event->getData());

Check failure on line 54 in src/EventSubscriber/WebformSubmissionDataEventSubscriber.php

View workflow job for this annotation

GitHub Actions / PHP - Code analysis (8.1, prefer-lowest)

Call to method getData() on an unknown class Drupal\webform_rest\Event\WebformSubmissionDataEvent.

Check failure on line 54 in src/EventSubscriber/WebformSubmissionDataEventSubscriber.php

View workflow job for this annotation

GitHub Actions / PHP - Code analysis (8.1, prefer-lowest)

Call to method getWebformSubmission() on an unknown class Drupal\webform_rest\Event\WebformSubmissionDataEvent.

Check failure on line 54 in src/EventSubscriber/WebformSubmissionDataEventSubscriber.php

View workflow job for this annotation

GitHub Actions / PHP - Code analysis (8.1, prefer-stable)

Call to method getData() on an unknown class Drupal\webform_rest\Event\WebformSubmissionDataEvent.

Check failure on line 54 in src/EventSubscriber/WebformSubmissionDataEventSubscriber.php

View workflow job for this annotation

GitHub Actions / PHP - Code analysis (8.1, prefer-stable)

Call to method getWebformSubmission() on an unknown class Drupal\webform_rest\Event\WebformSubmissionDataEvent.

if (!empty($linkedData)) {
$event->setData($event->getData() + ['linked' => $linkedData]);

Check failure on line 57 in src/EventSubscriber/WebformSubmissionDataEventSubscriber.php

View workflow job for this annotation

GitHub Actions / PHP - Code analysis (8.1, prefer-lowest)

Call to method getData() on an unknown class Drupal\webform_rest\Event\WebformSubmissionDataEvent.

Check failure on line 57 in src/EventSubscriber/WebformSubmissionDataEventSubscriber.php

View workflow job for this annotation

GitHub Actions / PHP - Code analysis (8.1, prefer-lowest)

Call to method setData() on an unknown class Drupal\webform_rest\Event\WebformSubmissionDataEvent.

Check failure on line 57 in src/EventSubscriber/WebformSubmissionDataEventSubscriber.php

View workflow job for this annotation

GitHub Actions / PHP - Code analysis (8.1, prefer-stable)

Call to method getData() on an unknown class Drupal\webform_rest\Event\WebformSubmissionDataEvent.

Check failure on line 57 in src/EventSubscriber/WebformSubmissionDataEventSubscriber.php

View workflow job for this annotation

GitHub Actions / PHP - Code analysis (8.1, prefer-stable)

Call to method setData() on an unknown class Drupal\webform_rest\Event\WebformSubmissionDataEvent.
}

$attachments = $this->buildAttachments($event->getWebformSubmission(), $event->getData());

Check failure on line 60 in src/EventSubscriber/WebformSubmissionDataEventSubscriber.php

View workflow job for this annotation

GitHub Actions / PHP - Code analysis (8.1, prefer-lowest)

Call to method getData() on an unknown class Drupal\webform_rest\Event\WebformSubmissionDataEvent.

Check failure on line 60 in src/EventSubscriber/WebformSubmissionDataEventSubscriber.php

View workflow job for this annotation

GitHub Actions / PHP - Code analysis (8.1, prefer-lowest)

Call to method getWebformSubmission() on an unknown class Drupal\webform_rest\Event\WebformSubmissionDataEvent.

Check failure on line 60 in src/EventSubscriber/WebformSubmissionDataEventSubscriber.php

View workflow job for this annotation

GitHub Actions / PHP - Code analysis (8.1, prefer-stable)

Call to method getData() on an unknown class Drupal\webform_rest\Event\WebformSubmissionDataEvent.

Check failure on line 60 in src/EventSubscriber/WebformSubmissionDataEventSubscriber.php

View workflow job for this annotation

GitHub Actions / PHP - Code analysis (8.1, prefer-stable)

Call to method getWebformSubmission() on an unknown class Drupal\webform_rest\Event\WebformSubmissionDataEvent.
if (!empty($attachments)) {
$event->setData($event->getData() + ['attachments' => $attachments]);

Check failure on line 62 in src/EventSubscriber/WebformSubmissionDataEventSubscriber.php

View workflow job for this annotation

GitHub Actions / PHP - Code analysis (8.1, prefer-lowest)

Call to method getData() on an unknown class Drupal\webform_rest\Event\WebformSubmissionDataEvent.

Check failure on line 62 in src/EventSubscriber/WebformSubmissionDataEventSubscriber.php

View workflow job for this annotation

GitHub Actions / PHP - Code analysis (8.1, prefer-lowest)

Call to method setData() on an unknown class Drupal\webform_rest\Event\WebformSubmissionDataEvent.

Check failure on line 62 in src/EventSubscriber/WebformSubmissionDataEventSubscriber.php

View workflow job for this annotation

GitHub Actions / PHP - Code analysis (8.1, prefer-stable)

Call to method getData() on an unknown class Drupal\webform_rest\Event\WebformSubmissionDataEvent.

Check failure on line 62 in src/EventSubscriber/WebformSubmissionDataEventSubscriber.php

View workflow job for this annotation

GitHub Actions / PHP - Code analysis (8.1, prefer-stable)

Call to method setData() on an unknown class Drupal\webform_rest\Event\WebformSubmissionDataEvent.
}
}

Expand Down Expand Up @@ -146,6 +147,14 @@
'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 All @@ -156,7 +165,7 @@
*/
public static function getSubscribedEvents() {
return [
WebformSubmissionDataEvent::class => ['onWebformSubmissionDataEvent'],

Check failure on line 168 in src/EventSubscriber/WebformSubmissionDataEventSubscriber.php

View workflow job for this annotation

GitHub Actions / PHP - Code analysis (8.1, prefer-lowest)

Class Drupal\webform_rest\Event\WebformSubmissionDataEvent not found.

Check failure on line 168 in src/EventSubscriber/WebformSubmissionDataEventSubscriber.php

View workflow job for this annotation

GitHub Actions / PHP - Code analysis (8.1, prefer-stable)

Class Drupal\webform_rest\Event\WebformSubmissionDataEvent not found.
];
}

Expand Down
Loading