From 3ea7d91614fed19e1228021e85d8e30d7c018de4 Mon Sep 17 00:00:00 2001 From: Ankit Pathak Date: Sun, 16 Jun 2024 21:08:02 +0530 Subject: [PATCH] Adding D11 support for nextjs. --- modules/next/.gitlab-ci.yml | 7 ++-- modules/next/composer.json | 2 +- .../modules/next_extras/next_extras.info.yml | 2 +- .../next_extras/src/NextCacheInvalidator.php | 3 +- .../next_graphql/next_graphql.info.yml | 2 +- .../next_jsonapi/next_jsonapi.info.yml | 2 +- .../src/NextJsonapiServiceProvider.php | 1 - .../next/modules/next_jwt/next_jwt.info.yml | 2 +- .../EventSubscriber/JwtEventSubscriber.php | 2 +- modules/next/next.info.yml | 2 +- modules/next/next.services.yml | 1 + .../EntityActionEventRevalidateSubscriber.php | 2 +- modules/next/src/Form/NextSettingsForm.php | 32 ++++--------------- modules/next/src/NextSettingsManager.php | 18 ++++++++--- .../next/src/Plugin/Next/Revalidator/Path.php | 2 +- .../src/Plugin/Next/SitePreviewer/Iframe.php | 5 +-- .../modules/next_tests/next_tests.info.yml | 1 - .../EntityActionEventSubscriber.php | 2 +- .../EntityRevalidatedEventSubscriber.php | 2 +- .../src/Kernel/NextSettingsManagerTest.php | 4 +-- .../SimpleOauthPreviewUrlGeneratorTest.php | 2 +- 21 files changed, 46 insertions(+), 50 deletions(-) diff --git a/modules/next/.gitlab-ci.yml b/modules/next/.gitlab-ci.yml index 68f905280..3a47a0ccb 100644 --- a/modules/next/.gitlab-ci.yml +++ b/modules/next/.gitlab-ci.yml @@ -52,8 +52,11 @@ include: # # Docs at https://git.drupalcode.org/project/gitlab_templates/-/blob/1.0.x/includes/include.drupalci.variables.yml ################ -# variables: -# SKIP_ESLINT: '1' +variables: + # SKIP_ESLINT: '1' + OPT_IN_TEST_PREVIOUS_MINOR: 1 + OPT_IN_TEST_NEXT_MINOR: 1 + OPT_IN_TEST_NEXT_MAJOR: 1 ################################################################################### # diff --git a/modules/next/composer.json b/modules/next/composer.json index 63e729775..f35970cee 100644 --- a/modules/next/composer.json +++ b/modules/next/composer.json @@ -17,6 +17,6 @@ "drupal/subrequests": "^3.0" }, "require-dev": { - "phpunit/phpunit": "^6.0 || ^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^8.0 || ^9.0 || ^10" } } diff --git a/modules/next/modules/next_extras/next_extras.info.yml b/modules/next/modules/next_extras/next_extras.info.yml index da9ecaf1e..f239c9a9c 100644 --- a/modules/next/modules/next_extras/next_extras.info.yml +++ b/modules/next/modules/next_extras/next_extras.info.yml @@ -1,7 +1,7 @@ name: Next.js Extras (Experimental) description: Adds extra (mostly experiemental) functionality to Next.js module type: module -core_version_requirement: ^9 || ^10 +core_version_requirement: ^9 || ^10 || ^11 package: Web services dependencies: - next:next diff --git a/modules/next/modules/next_extras/src/NextCacheInvalidator.php b/modules/next/modules/next_extras/src/NextCacheInvalidator.php index 3afc174f1..79374ffb3 100644 --- a/modules/next/modules/next_extras/src/NextCacheInvalidator.php +++ b/modules/next/modules/next_extras/src/NextCacheInvalidator.php @@ -143,7 +143,8 @@ public function invalidatePath(string $path, array $sites): void { } } catch (RequestException $exception) { - watchdog_exception('next_extras', $exception); + // Using logger service to log the exception. + $this->logger->error($exception); } } } diff --git a/modules/next/modules/next_graphql/next_graphql.info.yml b/modules/next/modules/next_graphql/next_graphql.info.yml index 12105a81d..0e50c6325 100644 --- a/modules/next/modules/next_graphql/next_graphql.info.yml +++ b/modules/next/modules/next_graphql/next_graphql.info.yml @@ -1,7 +1,7 @@ name: 'Next.js GraphQL' type: module description: 'GraphQL for Next.js' -core_version_requirement: ^9 || ^10 +core_version_requirement: ^9 || ^10 || ^11 package: Web services dependencies: - graphql:graphql diff --git a/modules/next/modules/next_jsonapi/next_jsonapi.info.yml b/modules/next/modules/next_jsonapi/next_jsonapi.info.yml index da67d7e1b..f2e112753 100644 --- a/modules/next/modules/next_jsonapi/next_jsonapi.info.yml +++ b/modules/next/modules/next_jsonapi/next_jsonapi.info.yml @@ -1,7 +1,7 @@ name: 'Next.js JSON:API' type: module description: 'JSON:API Helpers for Next.js' -core_version_requirement: ^9 || ^10 +core_version_requirement: ^9 || ^10 || ^11 package: Web services dependencies: - decoupled_router:decoupled_router diff --git a/modules/next/modules/next_jsonapi/src/NextJsonapiServiceProvider.php b/modules/next/modules/next_jsonapi/src/NextJsonapiServiceProvider.php index 210e19ff6..ee6432af0 100644 --- a/modules/next/modules/next_jsonapi/src/NextJsonapiServiceProvider.php +++ b/modules/next/modules/next_jsonapi/src/NextJsonapiServiceProvider.php @@ -15,7 +15,6 @@ class NextJsonapiServiceProvider extends ServiceProviderBase { */ public function alter(ContainerBuilder $container) { /** @var \Symfony\Component\DependencyInjection\Definition $definition */ - if ($container->hasDefinition('jsonapi.entity_resource')) { $definition = $container->getDefinition('jsonapi.entity_resource'); $definition->setClass('Drupal\next_jsonapi\Controller\EntityResource'); diff --git a/modules/next/modules/next_jwt/next_jwt.info.yml b/modules/next/modules/next_jwt/next_jwt.info.yml index 0943b180f..674c9e716 100644 --- a/modules/next/modules/next_jwt/next_jwt.info.yml +++ b/modules/next/modules/next_jwt/next_jwt.info.yml @@ -1,7 +1,7 @@ name: Next.js JWT (Experimental) type: module description: 'Generates preview URLs using JSON Web Token' -core_version_requirement: ^9 || ^10 +core_version_requirement: ^9 || ^10 || ^11 package: Web services dependencies: - next:next diff --git a/modules/next/modules/next_jwt/src/EventSubscriber/JwtEventSubscriber.php b/modules/next/modules/next_jwt/src/EventSubscriber/JwtEventSubscriber.php index 598a8ce07..b2bcb6560 100644 --- a/modules/next/modules/next_jwt/src/EventSubscriber/JwtEventSubscriber.php +++ b/modules/next/modules/next_jwt/src/EventSubscriber/JwtEventSubscriber.php @@ -43,7 +43,7 @@ public function __construct(AccountInterface $current_user, NextSettingsManagerI /** * {@inheritdoc} */ - public static function getSubscribedEvents() { + public static function getSubscribedEvents(): array { $events[JwtAuthEvents::GENERATE][] = ['setStandardClaims', 100]; $events[JwtAuthEvents::GENERATE][] = ['setDrupalClaims', 99]; return $events; diff --git a/modules/next/next.info.yml b/modules/next/next.info.yml index 42872eb2f..b7688b91b 100644 --- a/modules/next/next.info.yml +++ b/modules/next/next.info.yml @@ -1,7 +1,7 @@ name: Next.js description: Next.js + Drupal for Incremental Static Regeneration and Draft mode. type: module -core_version_requirement: ^9 || ^10 +core_version_requirement: ^9 || ^10 || ^11 package: Web services configure: entity.next_site.collection dependencies: diff --git a/modules/next/next.services.yml b/modules/next/next.services.yml index b5afca86c..7434c7738 100644 --- a/modules/next/next.services.yml +++ b/modules/next/next.services.yml @@ -21,6 +21,7 @@ services: '@config.factory', '@plugin.manager.next.site_previewer', '@plugin.manager.next.preview_url_generator', + '@logger.channel.next' ] next.preview_secret_generator: class: Drupal\next\PreviewSecretGenerator diff --git a/modules/next/src/EventSubscriber/EntityActionEventRevalidateSubscriber.php b/modules/next/src/EventSubscriber/EntityActionEventRevalidateSubscriber.php index 461f4d4ef..6f776dbc8 100644 --- a/modules/next/src/EventSubscriber/EntityActionEventRevalidateSubscriber.php +++ b/modules/next/src/EventSubscriber/EntityActionEventRevalidateSubscriber.php @@ -17,7 +17,7 @@ class EntityActionEventRevalidateSubscriber extends EntityActionEventSubscriberB /** * {@inheritdoc} */ - public static function getSubscribedEvents() { + public static function getSubscribedEvents(): array { $events[EntityEvents::ENTITY_ACTION] = ['onAction']; return $events; } diff --git a/modules/next/src/Form/NextSettingsForm.php b/modules/next/src/Form/NextSettingsForm.php index 9d1b41815..66f92360e 100644 --- a/modules/next/src/Form/NextSettingsForm.php +++ b/modules/next/src/Form/NextSettingsForm.php @@ -22,7 +22,7 @@ class NextSettingsForm extends ConfigFormBase { * * @var \Drupal\next\Plugin\SitePreviewerManagerInterface */ - protected $sitePreviewerManager; + protected SitePreviewerManagerInterface $sitePreviewerManager; /** * The preview url generator manager. @@ -31,34 +31,16 @@ class NextSettingsForm extends ConfigFormBase { */ protected PreviewUrlGeneratorManagerInterface $previewUrlGeneratorManager; - /** - * NextSettingsForm constructor. - * - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The config factory service. - * @param \Drupal\next\Plugin\SitePreviewerManagerInterface $site_previewer_manager - * The site previewer manager. - * @param \Drupal\next\Plugin\PreviewUrlGeneratorManagerInterface $preview_url_generator_manager - * The preview url generator manager. - */ - public function __construct(ConfigFactoryInterface $config_factory, SitePreviewerManagerInterface $site_previewer_manager, PreviewUrlGeneratorManagerInterface $preview_url_generator_manager = NULL) { - if (!$preview_url_generator_manager) { - @trigger_error('Calling NextSettingsForm::__construct() without the $preview_url_generator_manager argument is deprecated in next:1.3.0 and will be required in next:2.0.0. See https://www.drupal.org/node/3308330', E_USER_DEPRECATED); - // @codingStandardsIgnoreStart - $preview_url_generator_manager = \Drupal::service('plugin.manager.next.preview_url_generator'); - // @codingStandardsIgnoreEnd - } - - parent::__construct($config_factory); - $this->sitePreviewerManager = $site_previewer_manager; - $this->previewUrlGeneratorManager = $preview_url_generator_manager; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static($container->get('config.factory'), $container->get('plugin.manager.next.site_previewer'), $container->get('plugin.manager.next.preview_url_generator')); + $instance = parent::create($container); + + $instance->sitePreviewerManager = $container->get('plugin.manager.next.site_previewer'); + $instance->previewUrlGeneratorManager = $container->get('plugin.manager.next.preview_url_generator'); + + return $instance; } /** diff --git a/modules/next/src/NextSettingsManager.php b/modules/next/src/NextSettingsManager.php index fb7af1d12..ae761e030 100644 --- a/modules/next/src/NextSettingsManager.php +++ b/modules/next/src/NextSettingsManager.php @@ -9,6 +9,7 @@ use Drupal\next\Plugin\PreviewUrlGeneratorManagerInterface; use Drupal\next\Plugin\SitePreviewerInterface; use Drupal\next\Plugin\SitePreviewerManagerInterface; +use Psr\Log\LoggerInterface; /** * Provides a service for next settings. @@ -36,6 +37,13 @@ class NextSettingsManager implements NextSettingsManagerInterface { */ protected PreviewUrlGeneratorManagerInterface $previewUrlGeneratorManager; + /** + * A logger instance. + * + * @var \Psr\Log\LoggerInterface + */ + protected $logger; + /** * NextSettingsManager constructor. * @@ -45,11 +53,14 @@ class NextSettingsManager implements NextSettingsManagerInterface { * The site previewer plugin manager. * @param \Drupal\next\Plugin\PreviewUrlGeneratorManagerInterface $preview_url_generator_manager * The preview url generator plugin manager. + * @param \Psr\Log\LoggerInterface $logger + * The logger instance. */ - public function __construct(ConfigFactoryInterface $config, SitePreviewerManagerInterface $site_previewer_manager, PreviewUrlGeneratorManagerInterface $preview_url_generator_manager) { + public function __construct(ConfigFactoryInterface $config, SitePreviewerManagerInterface $site_previewer_manager, PreviewUrlGeneratorManagerInterface $preview_url_generator_manager, LoggerInterface $logger) { $this->config = $config; $this->sitePreviewerManager = $site_previewer_manager; $this->previewUrlGeneratorManager = $preview_url_generator_manager; + $this->logger = $logger; } /** @@ -86,7 +97,7 @@ public function getSitePreviewer(): ?SitePreviewerInterface { return $site_previewer; } catch (PluginException $exception) { - watchdog_exception('next_drupal', $exception); + $this->logger->error($exception); return NULL; } @@ -105,8 +116,7 @@ public function getPreviewUrlGenerator(): ?PreviewUrlGeneratorInterface { return $preview_url_generator; } catch (PluginException $exception) { - - watchdog_exception('next_drupal', $exception); + $this->logger->error($exception); return NULL; } diff --git a/modules/next/src/Plugin/Next/Revalidator/Path.php b/modules/next/src/Plugin/Next/Revalidator/Path.php index af95288e8..ed4fbfe87 100644 --- a/modules/next/src/Plugin/Next/Revalidator/Path.php +++ b/modules/next/src/Plugin/Next/Revalidator/Path.php @@ -116,7 +116,7 @@ public function revalidate(EntityActionEvent $event): bool { } } catch (\Exception $exception) { - watchdog_exception('next', $exception); + $this->logger->error($exception); $revalidated = FALSE; } } diff --git a/modules/next/src/Plugin/Next/SitePreviewer/Iframe.php b/modules/next/src/Plugin/Next/SitePreviewer/Iframe.php index d7a36b159..9b34ee884 100644 --- a/modules/next/src/Plugin/Next/SitePreviewer/Iframe.php +++ b/modules/next/src/Plugin/Next/SitePreviewer/Iframe.php @@ -211,8 +211,9 @@ public function render(EntityInterface $entity, array $sites) { // Handle revisions. if ($entity instanceof RevisionableInterface && !$entity->isDefaultRevision()) { - /** @var \Drupal\Core\Entity\RevisionableInterface $revision */ - $revision = $this->entityTypeManager->getStorage($entity->getEntityTypeId())->loadRevision($entity->getRevisionId()); + /** @var \Drupal\Core\Entity\RevisionableStorageInterface $entity_storage */ + $entity_storage = $this->entityTypeManager->getStorage($entity->getEntityTypeId()); + $revsion = $entity_storage->loadRevision($entity->getRevisionId()); $build['toolbar']['links']['#links']['status'] = [ 'title' => $this->t('Revision: @date', [ diff --git a/modules/next/tests/modules/next_tests/next_tests.info.yml b/modules/next/tests/modules/next_tests/next_tests.info.yml index 36cafe015..a53dfb5f1 100644 --- a/modules/next/tests/modules/next_tests/next_tests.info.yml +++ b/modules/next/tests/modules/next_tests/next_tests.info.yml @@ -2,6 +2,5 @@ name: Next.js tests description: Configures testing for Next.js type: module package: testing -core_version_requirement: ^8.8 || ^9 dependencies: - next:next diff --git a/modules/next/tests/modules/next_tests/src/EventSubscriber/EntityActionEventSubscriber.php b/modules/next/tests/modules/next_tests/src/EventSubscriber/EntityActionEventSubscriber.php index 8824c415c..7edd362e6 100644 --- a/modules/next/tests/modules/next_tests/src/EventSubscriber/EntityActionEventSubscriber.php +++ b/modules/next/tests/modules/next_tests/src/EventSubscriber/EntityActionEventSubscriber.php @@ -32,7 +32,7 @@ public function __construct(LoggerChannelInterface $logger) { /** * {@inheritdoc} */ - public static function getSubscribedEvents() { + public static function getSubscribedEvents(): array { $events[EntityEvents::ENTITY_ACTION] = ['onAction']; return $events; } diff --git a/modules/next/tests/modules/next_tests/src/EventSubscriber/EntityRevalidatedEventSubscriber.php b/modules/next/tests/modules/next_tests/src/EventSubscriber/EntityRevalidatedEventSubscriber.php index a30b30f83..0667b01fe 100644 --- a/modules/next/tests/modules/next_tests/src/EventSubscriber/EntityRevalidatedEventSubscriber.php +++ b/modules/next/tests/modules/next_tests/src/EventSubscriber/EntityRevalidatedEventSubscriber.php @@ -32,7 +32,7 @@ public function __construct(LoggerChannelInterface $logger) { /** * {@inheritdoc} */ - public static function getSubscribedEvents() { + public static function getSubscribedEvents(): array { $events[EntityEvents::ENTITY_REVALIDATED] = ['onRevalidated']; return $events; } diff --git a/modules/next/tests/src/Kernel/NextSettingsManagerTest.php b/modules/next/tests/src/Kernel/NextSettingsManagerTest.php index 4eb83a82f..b1904d42a 100644 --- a/modules/next/tests/src/Kernel/NextSettingsManagerTest.php +++ b/modules/next/tests/src/Kernel/NextSettingsManagerTest.php @@ -53,7 +53,7 @@ public function test() { $settings = $this->nextSettingsManager->all(); $this->assertSame('iframe', $settings['site_previewer']); $this->assertSame('simple_oauth', $settings['preview_url_generator']); - $this->assertSame(FALSE, $settings['debug']); + $this->assertFalse($settings['debug']); $this->assertFalse($this->nextSettingsManager->isDebug()); $this->container->get('config.factory') @@ -61,7 +61,7 @@ public function test() { ->set('debug', TRUE) ->save(); $settings = $this->nextSettingsManager->all(); - $this->assertSame(TRUE, $settings['debug']); + $this->assertTrue($settings['debug']); $this->assertTrue($this->nextSettingsManager->isDebug()); $this->assertInstanceOf(Iframe::class, $this->nextSettingsManager->getSitePreviewer()); diff --git a/modules/next/tests/src/Kernel/Plugin/SimpleOauthPreviewUrlGeneratorTest.php b/modules/next/tests/src/Kernel/Plugin/SimpleOauthPreviewUrlGeneratorTest.php index 9afc524ac..70be92574 100644 --- a/modules/next/tests/src/Kernel/Plugin/SimpleOauthPreviewUrlGeneratorTest.php +++ b/modules/next/tests/src/Kernel/Plugin/SimpleOauthPreviewUrlGeneratorTest.php @@ -160,7 +160,7 @@ public function testValidateSecret() { * @return array[] * An array of test data. */ - public function providerValidateForInvalidBody() { + public static function providerValidateForInvalidBody(): array { return [ [[], "Field 'path' is missing"], [['path' => '/node/1'], "Field 'timestamp' is missing"],