99use Symfony \Component \HttpFoundation \Request ;
1010
1111/**
12- * Creates a resource for retrieving webform submission data and fields .
12+ * Creates a rest resource for retrieving webform submissions .
1313 *
1414 * @RestResource(
15- * id = "webform_rest_all_form_submissions ",
16- * label = @Translation("Webform - All submissions for a form"),
15+ * id = "webform_rest_form_submissions ",
16+ * label = @Translation("Webform - submissions for a form"),
1717 * uri_paths = {
18- * "canonical" = "/webform_rest/{webform_id}/all "
18+ * "canonical" = "/webform_rest/{webform_id}/submissions "
1919 * }
2020 * )
2121 */
2222class WebformAllFormSubmissions extends ResourceBase {
23-
2423 /**
2524 * The current request.
2625 *
@@ -44,6 +43,8 @@ class WebformAllFormSubmissions extends ResourceBase {
4443
4544 /**
4645 * {@inheritdoc}
46+ *
47+ * @phpstan-param array<string, mixed> $configuration
4748 */
4849 public static function create (ContainerInterface $ container , array $ configuration , $ plugin_id , $ plugin_definition ) {
4950 $ instance = parent ::create ($ container , $ configuration , $ plugin_id , $ plugin_definition );
@@ -56,30 +57,23 @@ public static function create(ContainerInterface $container, array $configuratio
5657 }
5758
5859 /**
59- * Sets the current request.
60+ * Sets current request.
6061 *
61- * @param \Symfony\Component\HttpFoundation\Request $current_request
62+ * @param \Symfony\Component\HttpFoundation\Request $currentRequest
6263 * The current request.
63- *
64- * @return $this
65- * Class.
6664 */
67- protected function setCurrentRequest (Request $ current_request ) {
68- $ this ->currentRequest = $ current_request ;
69- return $ this ;
65+ protected function setCurrentRequest (Request $ currentRequest ): void {
66+ $ this ->currentRequest = $ currentRequest ;
7067 }
7168
7269 /**
73- * Retrieve all submissions for a given webform id .
70+ * Get submissions for a given webform.
7471 *
7572 * @param string $webform_id
7673 * Webform ID.
7774 *
7875 * @return \Drupal\rest\ModifiedResourceResponse
79- * HTTP response object containing webform submissions.
80- *
81- * @throws \Symfony\Component\HttpKernel\Exception\HttpException
82- * Throws HttpException in case of error.
76+ * Response object.
8377 */
8478 public function get (string $ webform_id ): ModifiedResourceResponse {
8579 if (empty ($ webform_id )) {
@@ -91,7 +85,7 @@ public function get(string $webform_id): ModifiedResourceResponse {
9185 return new ModifiedResourceResponse ($ errors , 400 );
9286 }
9387
94- // Webform access check .
88+ // Attempt finding webform .
9589 $ webform = $ this ->webformHelper ->getWebform ($ webform_id );
9690
9791 if (NULL === $ webform ) {
@@ -100,20 +94,21 @@ public function get(string $webform_id): ModifiedResourceResponse {
10094 'message ' => $ this ->t ('Could not find webform with id :webform_id ' , [':webform_id ' => $ webform_id ]),
10195 ],
10296 ];
97+
10398 return new ModifiedResourceResponse ($ errors , 400 );
10499 }
105100
101+ // Webform access check.
106102 if (!$ this ->webformHelper ->hasWebformAccess ($ webform , $ this ->webformHelper ->getCurrentUser ())) {
107103 $ errors = [
108104 'error ' => [
109105 'message ' => $ this ->t ('Access denied ' ),
110106 ],
111107 ];
108+
112109 return new ModifiedResourceResponse ($ errors , 401 );
113110 }
114111
115- $ submissionData = [];
116-
117112 $ result = ['webform_id ' => $ webform_id ];
118113
119114 // Query for webform submissions with this webform_id.
@@ -135,6 +130,8 @@ public function get(string $webform_id): ModifiedResourceResponse {
135130 $ query ->accessCheck (FALSE );
136131 $ sids = $ query ->execute ();
137132
133+ $ submissionData = [];
134+
138135 foreach ($ sids as $ sid ) {
139136 /** @var \Drupal\webform\WebformSubmissionInterface $webform_submission */
140137 $ webform_submission = $ this ->entityTypeManager ->getStorage ('webform_submission ' )->load ($ sid );
0 commit comments