diff --git a/src/GraphQL/Utility/FileUpload.php b/src/GraphQL/Utility/FileUpload.php index 26ddfba0e..eb01962b9 100644 --- a/src/GraphQL/Utility/FileUpload.php +++ b/src/GraphQL/Utility/FileUpload.php @@ -37,9 +37,9 @@ class FileUpload { use StringTranslationTrait; /** - * The file storage where we will create new file entities from. + * The entity storage for the 'file' entity type. * - * @var \Drupal\Core\Entity\EntityStorageInterface + * @var \Drupal\file\FileStorageInterface */ protected $fileStorage; @@ -137,7 +137,9 @@ public function __construct( ImageFactory $image_factory, FileValidatorInterface $file_validator, ) { - $this->fileStorage = $entityTypeManager->getStorage('file'); + /** @var \Drupal\file\FileStorageInterface $file_storage */ + $file_storage = $entityTypeManager->getStorage('file'); + $this->fileStorage = $file_storage; $this->currentUser = $currentUser; $this->mimeTypeGuesser = $mimeTypeGuesser; $this->fileSystem = $fileSystem; @@ -268,7 +270,7 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi try { // Begin building file entity. - /** @var \Drupal\Core\Entity\EntityInterface $file */ + /** @var \Drupal\file\FileInterface $file */ $file = $this->fileStorage->create([]); $file->setOwnerId($this->currentUser->id()); $file->setFilename($prepared_filename); @@ -323,8 +325,9 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi } $file->save(); - + dump($file); $response->setFileEntity($file); + dump($response->getFileEntity()); return $response; } finally { @@ -515,7 +518,7 @@ protected function prepareFilename(string $filename, array &$validators): string $passes_validation = FALSE; if (!empty($validators['FileExtension']['extensions'])) { - /** @var \Drupal\Core\Entity\EntityInterface $file */ + /** @var \Drupal\file\FileInterface $file */ $file = $this->fileStorage->create([]); $file->setFilename($filename); $passes_validation = empty($this->fileValidator->validate($file, $validators['FileExtension']['extensions'])); diff --git a/tests/modules/graphql_file_validate/graphql_file_validate.info.yml b/tests/modules/graphql_file_validate/graphql_file_validate.info.yml deleted file mode 100644 index 1443533b4..000000000 --- a/tests/modules/graphql_file_validate/graphql_file_validate.info.yml +++ /dev/null @@ -1,5 +0,0 @@ -type: module -name: GraphQL File Validate Test -description: Tests hook_file_validate() on uploads. -package: Testing -hidden: TRUE diff --git a/tests/modules/graphql_file_validate/graphql_file_validate.module b/tests/modules/graphql_file_validate/graphql_file_validate.module deleted file mode 100644 index ae89684be..000000000 --- a/tests/modules/graphql_file_validate/graphql_file_validate.module +++ /dev/null @@ -1,17 +0,0 @@ -getFileUri())) { - throw new \Exception('File does not exist during validation: ' . $file->getFileUri()); - } -} diff --git a/tests/src/Kernel/Framework/UploadFileServiceTest.php b/tests/src/Kernel/Framework/UploadFileServiceTest.php index c0307bd6b..54ea7a021 100644 --- a/tests/src/Kernel/Framework/UploadFileServiceTest.php +++ b/tests/src/Kernel/Framework/UploadFileServiceTest.php @@ -15,11 +15,6 @@ */ class UploadFileServiceTest extends GraphQLTestBase { - /** - * {@inheritdoc} - */ - protected static $modules = ['file', 'graphql_file_validate']; - /** * The FileUpload object we want to test, gets prepared in setUp(). * @@ -27,6 +22,13 @@ class UploadFileServiceTest extends GraphQLTestBase { */ protected $uploadService; + /** + * Modules to enable. + * + * @var array + */ + protected static $modules = ['file']; + /** * Gets the file path of the source file. * @@ -67,7 +69,7 @@ public function testSuccess(): void { 'file_directory' => 'test', ]); $file_entity = $file_upload_response->getFileEntity(); - + dump($file_entity); $this->assertSame('public://test/test.txt', $file_entity->getFileUri()); $this->assertFileExists($file_entity->getFileUri()); }