Skip to content

Commit

Permalink
FORMS-984: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jekuaitk committed Oct 20, 2023
1 parent 872880a commit 66a0e19
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions src/Plugin/rest/resource/WebformAllFormSubmissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"
* }
* )
*/
Expand Down Expand Up @@ -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) {

Check failure on line 64 in src/Plugin/rest/resource/WebformAllFormSubmissions.php

View workflow job for this annotation

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

Method Drupal\os2forms_rest_api\Plugin\rest\resource\WebformAllFormSubmissions::setCurrentRequest() has no return type specified.

Check failure on line 64 in src/Plugin/rest/resource/WebformAllFormSubmissions.php

View workflow job for this annotation

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

Method Drupal\os2forms_rest_api\Plugin\rest\resource\WebformAllFormSubmissions::setCurrentRequest() has no return type specified.
$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)) {
Expand All @@ -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) {
Expand All @@ -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.
Expand All @@ -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);
Expand Down

0 comments on commit 66a0e19

Please sign in to comment.