You are here

protected function FileUpload::validate in GraphQL 8.4

Validates the file.

Parameters

\Drupal\file\FileInterface $file: The file entity to validate.

array $validators: An array of upload validators to pass to file_validate().

\Drupal\graphql\GraphQL\Response\FileUploadResponse $response: The response where validation errors will be added.

Return value

bool TRUE if validation was successful, FALSE otherwise.

Throws

\Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException Thrown when there are file validation errors.

1 call to FileUpload::validate()
FileUpload::saveFileUpload in src/GraphQL/Utility/FileUpload.php
Validates an uploaded file, saves it and returns a file upload response.

File

src/GraphQL/Utility/FileUpload.php, line 350

Class

FileUpload
Service to manage file uploads within GraphQL mutations.

Namespace

Drupal\graphql\GraphQL\Utility

Code

protected function validate(FileInterface $file, array $validators, FileUploadResponse $response) : bool {
  $violations = $file
    ->validate();
  if ($violations
    ->count()) {
    foreach ($violations as $violation) {
      $response
        ->addViolation($violation
        ->getMessage());
      return FALSE;
    }
  }
  return TRUE;
}