Skip to content

Commit 4e042b7

Browse files
authored
refactor(drupal9): Drop Drupal 9 support (#1396)
1 parent e29468f commit 4e042b7

File tree

9 files changed

+25
-35
lines changed

9 files changed

+25
-35
lines changed

.github/workflows/testing.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,13 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
php-versions: ['7.3', '7.4', '8.0', '8.1']
17-
# Keep testing Drupal 9 untill 6 months after it got unsupported, so
18-
# untill May 1st 2024.
19-
drupal-core: ['9.5.x']
16+
php-versions: ['8.1', '8.2']
17+
drupal-core: ['10.2.x']
2018
phpstan: ['0']
2119
include:
22-
# Extra runs to also test on latest Drupal 10.
20+
# Extra run to test older supported Drupal 10.1.x.
2321
- php-versions: '8.1'
24-
drupal-core: '10.2.x'
25-
phpstan: '0'
26-
- php-versions: '8.2'
27-
drupal-core: '10.2.x'
22+
drupal-core: '10.1.x'
2823
phpstan: '0'
2924
# We only need to run PHPStan once on the latest PHP version.
3025
- php-versions: '8.3'

examples/graphql_composable/graphql_composable.info.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ package: GraphQL
55
dependencies:
66
- graphql:graphql
77
- node:node
8-
core_version_requirement: ^9.3 || ^10
8+
core_version_requirement: ^10.1

examples/graphql_example/graphql_examples.info.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ package: GraphQL
55
dependencies:
66
- graphql:graphql
77
- node:node
8-
core_version_requirement: ^9.3 || ^10
8+
core_version_requirement: ^10.1

graphql.info.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ type: module
33
description: 'Base module for integrating GraphQL with Drupal.'
44
package: GraphQL
55
configure: graphql.config_page
6-
core_version_requirement: ^9.3 || ^10
6+
core_version_requirement: ^10.1
77
dependencies:
88
- typed_data:typed_data

src/GraphQL/Execution/Executor.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Drupal\graphql\GraphQL\Execution;
44

5+
use Drupal\Component\Datetime\TimeInterface;
56
use Drupal\Core\Cache\Cache;
67
use Drupal\Core\Cache\CacheableMetadata;
78
use Drupal\Core\Cache\CacheBackendInterface;
@@ -22,7 +23,6 @@
2223
use GraphQL\Utils\AST;
2324
use Symfony\Component\DependencyInjection\ContainerInterface;
2425
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
25-
use Symfony\Component\HttpFoundation\RequestStack;
2626

2727
/**
2828
* Executes GraphQL queries with cache lookup.
@@ -51,11 +51,9 @@ class Executor implements ExecutorImplementation {
5151
protected $contextsManager;
5252

5353
/**
54-
* The request stack.
55-
*
56-
* @var \Symfony\Component\HttpFoundation\RequestStack
54+
* The date/time service.
5755
*/
58-
protected $requestStack;
56+
protected TimeInterface $time;
5957

6058
/**
6159
* The event dispatcher.
@@ -127,8 +125,8 @@ class Executor implements ExecutorImplementation {
127125
* The cache contexts manager service.
128126
* @param \Drupal\Core\Cache\CacheBackendInterface $cacheBackend
129127
* The cache backend for caching query results.
130-
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
131-
* The request stack.
128+
* @param \Drupal\Component\Datetime\TimeInterface $time
129+
* The date/time service.
132130
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
133131
* The event dispatcher.
134132
* @param \GraphQL\Executor\Promise\PromiseAdapter $adapter
@@ -143,7 +141,7 @@ class Executor implements ExecutorImplementation {
143141
public function __construct(
144142
CacheContextsManager $contextsManager,
145143
CacheBackendInterface $cacheBackend,
146-
RequestStack $requestStack,
144+
TimeInterface $time,
147145
EventDispatcherInterface $dispatcher,
148146
PromiseAdapter $adapter,
149147
Schema $schema,
@@ -156,7 +154,7 @@ public function __construct(
156154
) {
157155
$this->contextsManager = $contextsManager;
158156
$this->cacheBackend = $cacheBackend;
159-
$this->requestStack = $requestStack;
157+
$this->time = $time;
160158
$this->dispatcher = $dispatcher;
161159

162160
$this->adapter = $adapter;
@@ -198,7 +196,7 @@ public static function create(
198196
return new static(
199197
$container->get('cache_contexts_manager'),
200198
$container->get('cache.graphql.results'),
201-
$container->get('request_stack'),
199+
$container->get('datetime.time'),
202200
$container->get('event_dispatcher'),
203201
$adapter,
204202
$schema,
@@ -444,8 +442,7 @@ protected function cacheWrite($prefix, CacheableExecutionResult $result) {
444442
* @see \Drupal\Core\Cache\CacheBackendInterface::set()
445443
*/
446444
protected function maxAgeToExpire($maxAge) {
447-
// @todo Can be removed when D9 support is dropped.
448-
$time = $this->requestStack->getMainRequest()->server->get('REQUEST_TIME');
445+
$time = $this->time->getRequestTime();
449446
return ($maxAge === Cache::PERMANENT) ? Cache::PERMANENT : (int) $time + $maxAge;
450447
}
451448

src/GraphQL/Utility/FileUpload.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi
193193
switch ($uploaded_file->getError()) {
194194
case UPLOAD_ERR_INI_SIZE:
195195
case UPLOAD_ERR_FORM_SIZE:
196-
// @todo Drupal 9 compatibility, needs to be converted to ByteSizeMarkup
197-
// later.
196+
// @todo Drupal 10.1 compatibility, needs to be converted to
197+
// ByteSizeMarkup later.
198198
// @phpstan-ignore-next-line
199199
$maxUploadSize = format_size($this->getMaxUploadSize($settings));
200200
$response->addViolation($this->t('The file @file could not be saved because it exceeds @maxsize, the maximum allowed size for uploads.', [
@@ -271,7 +271,7 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi
271271
$file->setSize(@filesize($temp_file_path));
272272

273273
// Validate against file_validate() first with the temporary path.
274-
// @todo Drupal 9 compatibility, needs to be converted to file validate
274+
// @todo Drupal 10.1 compatibility, needs to be converted to file validate
275275
// service later.
276276
// @phpstan-ignore-next-line
277277
$errors = file_validate($file, $validators);
@@ -505,7 +505,7 @@ protected function prepareFilename(string $filename, array &$validators): string
505505
/** @var \Drupal\file\FileInterface $file */
506506
$file = $this->fileStorage->create([]);
507507
$file->setFilename($filename);
508-
// @todo Drupal 9 compatibility, needs to be converted to file
508+
// @todo Drupal 10.1 compatibility, needs to be converted to file
509509
// validator service later.
510510
// @phpstan-ignore-next-line
511511
$passes_validation = empty(file_validate_extensions($file, $validators['file_validate_extensions'][0]));

src/Routing/QueryRouteEnhancer.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ protected function assertValidPostRequestHeaders(Request $request) : void {
136136
// Allow other origins as configured in the CORS policy.
137137
if (!empty($this->corsOptions['enabled'])) {
138138
$cors_service = new CorsService($this->corsOptions);
139-
// Drupal 9 compatibility, method name has changed in Drupal 10.
140-
// @phpstan-ignore-next-line
141-
if ($cors_service->isActualRequestAllowed($request)) {
139+
if ($cors_service->isOriginAllowed($request)) {
142140
return;
143141
}
144142
}

tests/src/Kernel/DataProducer/EntityDefinitionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,8 @@ enum FieldTypes {
497497
])
498498
);
499499

500-
// @todo Different description between Drupal 9 and 10, can be removed when
501-
// Drupal 9 support is dropped.
500+
// @todo Different description between Drupal 10.1 and 10.2, can be removed
501+
// when Drupal 10.1 support is dropped.
502502
$this->fullDefinitionResult['entityDefinition']['fields'][11]['description'] =
503503
$this->container->get('entity_field.manager')->getBaseFieldDefinitions('node')['created']->getDescription();
504504
}

tests/src/Kernel/DataProducer/EntityReferenceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use Drupal\node\Entity\NodeType;
88
use Drupal\Tests\graphql\Kernel\GraphQLTestBase;
99

10-
// @todo Drupal 9 compatibility: use the deprecated trait for Drupal 9.
11-
if (strpos(\Drupal::VERSION, '9') === 0) {
10+
// @todo Drupal 10.1 compatibility: use the deprecated trait for Drupal 10.1.
11+
if (strpos(\Drupal::VERSION, '10.1') === 0) {
1212

1313
/**
1414
* Helper trait for compatibility with Drupal 9.

0 commit comments

Comments
 (0)