Skip to content

Commit

Permalink
Adding D11 support for nextjs.
Browse files Browse the repository at this point in the history
  • Loading branch information
apathak18 committed Jun 16, 2024
1 parent f56c243 commit 3ea7d91
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 50 deletions.
7 changes: 5 additions & 2 deletions modules/next/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

###################################################################################
#
Expand Down
2 changes: 1 addition & 1 deletion modules/next/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion modules/next/modules/next_extras/next_extras.info.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/next/modules/next_graphql/next_graphql.info.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/next/modules/next_jsonapi/next_jsonapi.info.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion modules/next/modules/next_jwt/next_jwt.info.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion modules/next/next.info.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
1 change: 1 addition & 0 deletions modules/next/next.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
32 changes: 7 additions & 25 deletions modules/next/src/Form/NextSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class NextSettingsForm extends ConfigFormBase {
*
* @var \Drupal\next\Plugin\SitePreviewerManagerInterface
*/
protected $sitePreviewerManager;
protected SitePreviewerManagerInterface $sitePreviewerManager;

/**
* The preview url generator manager.
Expand All @@ -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;
}

/**
Expand Down
18 changes: 14 additions & 4 deletions modules/next/src/NextSettingsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -36,6 +37,13 @@ class NextSettingsManager implements NextSettingsManagerInterface {
*/
protected PreviewUrlGeneratorManagerInterface $previewUrlGeneratorManager;

/**
* A logger instance.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;

/**
* NextSettingsManager constructor.
*
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/next/src/Plugin/Next/Revalidator/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function revalidate(EntityActionEvent $event): bool {
}
}
catch (\Exception $exception) {
watchdog_exception('next', $exception);
$this->logger->error($exception);
$revalidated = FALSE;
}
}
Expand Down
5 changes: 3 additions & 2 deletions modules/next/src/Plugin/Next/SitePreviewer/Iframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand Down
1 change: 0 additions & 1 deletion modules/next/tests/modules/next_tests/next_tests.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions modules/next/tests/src/Kernel/NextSettingsManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ 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')
->getEditable('next.settings')
->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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down

0 comments on commit 3ea7d91

Please sign in to comment.