diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 7c74231a0..8d198a1b7 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -17,10 +17,6 @@ jobs: drupal-core: ['10.3.x'] phpstan: ['0'] include: - # Extra run to test older supported Drupal 10.1.x. - - php-versions: '8.1' - drupal-core: '10.1.x' - phpstan: '0' # Extra run to test older supported Drupal 10.2.x. - php-versions: '8.1' drupal-core: '10.2.x' diff --git a/graphql.info.yml b/graphql.info.yml index 90852febe..8b43f0087 100644 --- a/graphql.info.yml +++ b/graphql.info.yml @@ -3,6 +3,6 @@ type: module description: 'Base module for integrating GraphQL with Drupal.' package: GraphQL configure: graphql.config_page -core_version_requirement: ^10.1 || ^11 +core_version_requirement: ^10.2 || ^11 dependencies: - typed_data:typed_data diff --git a/graphql.services.yml b/graphql.services.yml index ad0c2c9a7..23c01419f 100644 --- a/graphql.services.yml +++ b/graphql.services.yml @@ -184,6 +184,7 @@ services: - '@renderer' - '@event_dispatcher' - '@image.factory' + - '@file.validator' plugin.manager.graphql.persisted_query: class: Drupal\graphql\Plugin\PersistedQueryPluginManager diff --git a/src/GraphQL/Utility/FileUpload.php b/src/GraphQL/Utility/FileUpload.php index 7543ea5c7..6d4cb62ef 100644 --- a/src/GraphQL/Utility/FileUpload.php +++ b/src/GraphQL/Utility/FileUpload.php @@ -17,9 +17,11 @@ use Drupal\Core\Render\RenderContext; use Drupal\Core\Render\RendererInterface; use Drupal\Core\Session\AccountProxyInterface; +use Drupal\Core\StringTranslation\ByteSizeMarkup; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Utility\Token; use Drupal\file\FileInterface; +use Drupal\file\Validation\FileValidatorInterface; use Drupal\graphql\GraphQL\Response\FileUploadResponse; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\File\UploadedFile; @@ -111,6 +113,13 @@ class FileUpload { */ protected $imageFactory; + /** + * The file validator service. + * + * @var \Drupal\file\Validation\FileValidatorInterface + */ + protected FileValidatorInterface $fileValidator; + /** * Constructor. */ @@ -126,6 +135,7 @@ public function __construct( RendererInterface $renderer, EventDispatcherInterface $eventDispatcher, ImageFactory $image_factory, + FileValidatorInterface $file_validator, ) { /** @var \Drupal\file\FileStorageInterface $file_storage */ $file_storage = $entityTypeManager->getStorage('file'); @@ -140,6 +150,7 @@ public function __construct( $this->renderer = $renderer; $this->eventDispatcher = $eventDispatcher; $this->imageFactory = $image_factory; + $this->fileValidator = $file_validator; } /** @@ -193,10 +204,7 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi switch ($uploaded_file->getError()) { case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: - // @todo Drupal 10.1 compatibility, needs to be converted to - // ByteSizeMarkup later. - // @phpstan-ignore-next-line - $maxUploadSize = format_size($this->getMaxUploadSize($settings)); + $maxUploadSize = ByteSizeMarkup::create($this->getMaxUploadSize($settings)); $response->addViolation($this->t('The file @file could not be saved because it exceeds @maxsize, the maximum allowed size for uploads.', [ '@file' => $uploaded_file->getClientOriginalName(), '@maxsize' => $maxUploadSize, @@ -272,11 +280,8 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi // before it is saved. $file->setSize(@filesize($temp_file_path)); - // Validate against file_validate() first with the temporary path. - // @todo Drupal 10.1 compatibility, needs to be converted to file validate - // service later. - // @phpstan-ignore-next-line - $errors = file_validate($file, $validators); + // Validate against fileValidator first with the temporary path. + $errors = $this->fileValidator->validate($file, $validators); $maxResolution = $settings['max_resolution'] ?? 0; $minResolution = $settings['min_resolution'] ?? 0; if (!empty($maxResolution) || !empty($minResolution)) { diff --git a/tests/src/Kernel/GraphQLTestBase.php b/tests/src/Kernel/GraphQLTestBase.php index 20425566f..f60b5338d 100644 --- a/tests/src/Kernel/GraphQLTestBase.php +++ b/tests/src/Kernel/GraphQLTestBase.php @@ -50,6 +50,7 @@ abstract class GraphQLTestBase extends KernelTestBase { 'content_translation', 'entity_reference_test', 'field', + 'file', 'menu_link_content', 'link', 'typed_data',