From 66a0e193ce99263958fd85a4a420adac8fe9129b Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Fri, 20 Oct 2023 13:51:29 +0200 Subject: [PATCH] FORMS-984: Cleanup --- .../resource/WebformAllFormSubmissions.php | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/Plugin/rest/resource/WebformAllFormSubmissions.php b/src/Plugin/rest/resource/WebformAllFormSubmissions.php index f3e1892..b790783 100644 --- a/src/Plugin/rest/resource/WebformAllFormSubmissions.php +++ b/src/Plugin/rest/resource/WebformAllFormSubmissions.php @@ -9,13 +9,13 @@ use Symfony\Component\HttpFoundation\Request; /** - * Creates a resource for retrieving webform submission data and fields. + * Creates a rest resource for retrieving webform submissions. * * @RestResource( - * id = "webform_rest_all_form_submissions", - * label = @Translation("Webform - All submissions for a form"), + * id = "webform_rest_form_submissions", + * label = @Translation("Webform - submissions for a form"), * uri_paths = { - * "canonical" = "/webform_rest/{webform_id}/all" + * "canonical" = "/webform_rest/{webform_id}/submissions" * } * ) */ @@ -56,30 +56,23 @@ public static function create(ContainerInterface $container, array $configuratio } /** - * Sets the current request. + * Sets current request. * - * @param \Symfony\Component\HttpFoundation\Request $current_request + * @param \Symfony\Component\HttpFoundation\Request $request * The current request. - * - * @return $this - * Class. */ - protected function setCurrentRequest(Request $current_request) { - $this->currentRequest = $current_request; - return $this; + protected function setCurrentRequest(Request $request) { + $this->currentRequest = $request; } /** - * Retrieve all submissions for a given webform id. + * Get submissions for a given webform. * * @param string $webform_id * Webform ID. * * @return \Drupal\rest\ModifiedResourceResponse - * HTTP response object containing webform submissions. - * - * @throws \Symfony\Component\HttpKernel\Exception\HttpException - * Throws HttpException in case of error. + * Response object. */ public function get(string $webform_id): ModifiedResourceResponse { if (empty($webform_id)) { @@ -91,7 +84,7 @@ public function get(string $webform_id): ModifiedResourceResponse { return new ModifiedResourceResponse($errors, 400); } - // Webform access check. + // Attempt finding webform. $webform = $this->webformHelper->getWebform($webform_id); if (NULL === $webform) { @@ -100,20 +93,21 @@ public function get(string $webform_id): ModifiedResourceResponse { 'message' => $this->t('Could not find webform with id :webform_id', [':webform_id' => $webform_id]), ], ]; + return new ModifiedResourceResponse($errors, 400); } + // Webform access check. if (!$this->webformHelper->hasWebformAccess($webform, $this->webformHelper->getCurrentUser())) { $errors = [ 'error' => [ 'message' => $this->t('Access denied'), ], ]; + return new ModifiedResourceResponse($errors, 401); } - $submissionData = []; - $result = ['webform_id' => $webform_id]; // Query for webform submissions with this webform_id. @@ -135,6 +129,8 @@ public function get(string $webform_id): ModifiedResourceResponse { $query->accessCheck(FALSE); $sids = $query->execute(); + $submissionData = []; + foreach ($sids as $sid) { /** @var \Drupal\webform\WebformSubmissionInterface $webform_submission */ $webform_submission = $this->entityTypeManager->getStorage('webform_submission')->load($sid);