-
Notifications
You must be signed in to change notification settings - Fork 1
Attachments data #3
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
diff --git a/src/Event/WebformSubmissionDataEvent.php b/src/Event/WebformSubmissionDataEvent.php | ||
new file mode 100644 | ||
index 0000000..c378f45 | ||
--- /dev/null | ||
+++ b/src/Event/WebformSubmissionDataEvent.php | ||
@@ -0,0 +1,52 @@ | ||
+<?php | ||
+ | ||
+namespace Drupal\webform_rest\Event; | ||
+ | ||
+use Drupal\Component\EventDispatcher\Event; | ||
+use Drupal\webform\WebformSubmissionInterface; | ||
+ | ||
+/** | ||
+ * Class WebformSubmissionDataEvent, an event to modify the data part of the response sent from calling GET webform submission. | ||
+ */ | ||
+class WebformSubmissionDataEvent extends Event | ||
+{ | ||
+ /** | ||
+ * @var WebformSubmissionInterface | ||
+ */ | ||
+ private WebformSubmissionInterface $webformSubmission; | ||
+ | ||
+ /** | ||
+ * @var array | ||
+ */ | ||
+ private array $data; | ||
+ | ||
+ /** | ||
+ * Construct for injection dependency. | ||
+ * | ||
+ * @param array $data | ||
+ * @param WebformSubmissionInterface $webformSubmission | ||
+ */ | ||
+ public function __construct(WebformSubmissionInterface $webformSubmission, array $data) { | ||
+ $this->webformSubmission = $webformSubmission; | ||
+ $this->setData($data); | ||
+ } | ||
+ | ||
+ /** | ||
+ * @return WebformSubmissionInterface | ||
+ */ | ||
+ public function getWebformSubmission(): WebformSubmissionInterface | ||
+ { | ||
+ return $this->webformSubmission; | ||
+ } | ||
+ | ||
+ public function getData(): array | ||
+ { | ||
+ return $this->data; | ||
+ } | ||
+ | ||
+ public function setData(array $data) | ||
+ { | ||
+ $this->data = $data; | ||
+ return $this; | ||
+ } | ||
+} | ||
diff --git a/src/Plugin/rest/resource/WebformSubmissionResource.php b/src/Plugin/rest/resource/WebformSubmissionResource.php | ||
index d2e08c5..a9cacf7 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; | ||
use Drupal\webform\WebformSubmissionForm; | ||
use Drupal\rest\Plugin\ResourceBase; | ||
use Drupal\rest\ModifiedResourceResponse; | ||
+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; | ||
|
||
+ /** | ||
+ * An event dispatcher instance to use for dispatching events. | ||
+ * | ||
+ * @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface | ||
+ */ | ||
+ protected $eventDispatcher; | ||
+ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
@@ -42,6 +50,7 @@ class WebformSubmissionResource extends ResourceBase { | ||
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition); | ||
$instance->entityTypeManager = $container->get('entity_type.manager'); | ||
$instance->request = $container->get('request_stack'); | ||
+ $instance->eventDispatcher = $container->get('event_dispatcher'); | ||
return $instance; | ||
} | ||
|
||
@@ -91,9 +100,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); | ||
+ | ||
$response = [ | ||
'entity' => $webform_submission, | ||
- 'data' => $data, | ||
+ 'data' => $event->getData(), | ||
]; | ||
|
||
// Return the submission. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.