Skip to content

Commit b62295a

Browse files
committed
PR feedback changes.
1 parent 0613dbb commit b62295a

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

src/GraphQL/Response/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function addViolation($message, array $properties = []): void {
2727
/**
2828
* {@inheritdoc}
2929
*/
30-
public function addViolations($messages, array $properties = []): void {
30+
public function addViolations(array $messages, array $properties = []): void {
3131
foreach ($messages as $message) {
3232
$this->addViolation($message, $properties);
3333
}

src/GraphQL/Response/ResponseInterface.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
namespace Drupal\graphql\GraphQL\Response;
66

7-
use Symfony\Component\Validator\ConstraintViolationListInterface;
8-
97
/**
108
* Response interface used for GraphQL responses.
119
*/
@@ -14,7 +12,7 @@ interface ResponseInterface {
1412
/**
1513
* Adds the violation.
1614
*
17-
* @param string|\Drupal\Core\StringTranslation\TranslatableMarkup|\Symfony\Component\Validator\ConstraintViolationListInterface $message
15+
* @param string|\Drupal\Core\StringTranslation\TranslatableMarkup $message
1816
* Violation message.
1917
* @param array $properties
2018
* Other properties related to the violation.
@@ -24,12 +22,12 @@ public function addViolation($message, array $properties = []): void;
2422
/**
2523
* Adds multiple violations.
2624
*
27-
* @param string[]|\Drupal\Core\StringTranslation\TranslatableMarkup[]|\Symfony\Component\Validator\ConstraintViolationListInterface $messages
25+
* @param string[]|\Drupal\Core\StringTranslation\TranslatableMarkup[] $messages
2826
* Violation messages.
2927
* @param array $properties
3028
* Other properties related to the violation.
3129
*/
32-
public function addViolations(array|ConstraintViolationListInterface $messages, array $properties = []): void;
30+
public function addViolations(array $messages, array $properties = []): void;
3331

3432
/**
3533
* Gets the violations.

src/GraphQL/Utility/FileUpload.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,13 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi
281281
$file->setSize(@filesize($temp_file_path));
282282

283283
// Validate against fileValidator first with the temporary path.
284-
/** @var \Symfony\Component\Validator\ConstraintViolationListInterface $errors */
285-
$errors = $this->fileValidator->validate($file, $validators);
286-
if (count($errors) > 0) {
287-
$response->addViolations($errors);
288-
return $response;
284+
/** @var \Symfony\Component\Validator\ConstraintViolationListInterface $file_validate_errors */
285+
$file_validate_errors = $this->fileValidator->validate($file, $validators);
286+
$errors = [];
287+
if (count($file_validate_errors) > 0) {
288+
foreach ($file_validate_errors as $violation) {
289+
$errors[] = $violation->getMessage();
290+
}
289291
}
290292

291293
// Validate Image resolution.
@@ -294,11 +296,14 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi
294296
if (!empty($maxResolution) || !empty($minResolution)) {
295297
$image_resolution_errors = $this->validateFileImageResolution($file, $maxResolution, $minResolution);
296298
if (!empty($image_resolution_errors)) {
297-
$response->addViolations($image_resolution_errors);
298-
return $response;
299+
$errors = array_merge($errors, $image_resolution_errors);
299300
}
300301
}
301302

303+
if (!empty($errors)) {
304+
$response->addViolations($errors);
305+
return $response;
306+
}
302307
$file->setFileUri($file_uri);
303308
// Move the file to the correct location after validation. Use
304309
// FileSystemInterface::EXISTS_ERROR as the file location has already been

src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function resolve(FileInterface $entity = NULL, $style, RefinableCacheable
103103
// @phpstan-ignore-next-line
104104
$height = $entity->height;
105105

106-
if (!isset($width) || !isset($height)) {
106+
if ($width == NULL || $height == NULL) {
107107
/** @var \Drupal\Core\Image\ImageInterface $image */
108108
$image = \Drupal::service('image.factory')->get($entity->getFileUri());
109109
if ($image->isValid()) {

0 commit comments

Comments
 (0)