Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding D11 support for nextjs. #778

Merged
merged 12 commits into from
Oct 4, 2024
6 changes: 6 additions & 0 deletions .github/workflows/next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ jobs:
- "10.0.x"
- "10.1.x"
- "10.2.x"
- "10.3.x"
- "11.0.x"
exclude:
- drupal: "10.0.x"
php: "8.3"
- drupal: "10.1.x"
php: "8.3"
- drupal: "11.0.x"
php: "8.1"
- drupal: "11.0.x"
php: "8.2"
Comment on lines +32 to +35
Copy link
Contributor

@yobottehg yobottehg Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

11.0 requires PHP 8.3

Copy link
Contributor Author

@apathak18 apathak18 Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yobottehg Correct!!
Pipeline is running on 8.3
see: Screenshot 2024-08-06 at 3 02 27 PM

this configuration is to exclude running with 8.1, 8.2 versions of php for Drupal 11

name: Drupal ${{ matrix.drupal }} - PHP ${{ matrix.php }}
services:
mysql:
Expand Down
8 changes: 5 additions & 3 deletions modules/next/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +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"
apathak18 marked this conversation as resolved.
Show resolved Hide resolved
}
}
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: ^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->getMessage());
}
}
}
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: ^10.1 || ^11
apathak18 marked this conversation as resolved.
Show resolved Hide resolved
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: ^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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\user\Entity\User;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\InputBag;
use Symfony\Component\HttpFoundation\Request;

/**
Expand Down Expand Up @@ -91,14 +91,14 @@ public function testPageLimit() {

// Default using \Drupal\jsonapi\Query\OffsetPage::SIZE_MAX.
$request = Request::create('/jsonapi/node/article');
$request->query = new ParameterBag();
$request->query = new InputBag();
$response = $entity_resource->getCollection($resource_type, $request);
$data = $response->getResponseData()->getData();
$this->assertSame(50, $data->count());

// With page limit.
$request = Request::create('/jsonapi/node/article');
$request->query = new ParameterBag([
$request->query = new InputBag([
'page' => [
'limit' => 10,
],
Expand All @@ -109,7 +109,7 @@ public function testPageLimit() {

// With page limit over size max.
$request = Request::create('/jsonapi/node/article');
$request->query = new ParameterBag([
$request->query = new InputBag([
'page' => [
'limit' => 100,
],
Expand All @@ -120,7 +120,7 @@ public function testPageLimit() {

// With page limit and offset.
$request = Request::create('/jsonapi/node/article');
$request->query = new ParameterBag([
$request->query = new InputBag([
'page' => [
'offset' => 2,
'limit' => 5,
Expand All @@ -132,7 +132,7 @@ public function testPageLimit() {

// With fields as sparse fieldset.
$request = Request::create('/jsonapi/node/article');
$request->query = new ParameterBag([
$request->query = new InputBag([
'fields' => [
'node--article' => 'title',
],
Expand All @@ -143,7 +143,7 @@ public function testPageLimit() {

// Using sparse fieldset path override.
$request = Request::create('/jsonapi/node/article');
$request->query = new ParameterBag([
$request->query = new InputBag([
'fields' => [
'node--article' => 'path,title',
],
Expand All @@ -154,7 +154,7 @@ public function testPageLimit() {

// Using sparse fieldset path override and limit.
$request = Request::create('/jsonapi/node/article');
$request->query = new ParameterBag([
$request->query = new InputBag([
'fields' => [
'node--article' => 'path,title',
],
Expand All @@ -168,7 +168,7 @@ public function testPageLimit() {

// Using sparse fieldset path override and limit.
$request = Request::create('/jsonapi/node/article');
$request->query = new ParameterBag([
$request->query = new InputBag([
'fields' => [
'node--article' => 'path,title',
],
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: ^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: ^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->getMessage());

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->getMessage());

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->getMessage());
$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());
$revision = $entity_storage->loadRevision($entity->getRevisionId());

$build['toolbar']['links']['#links']['status'] = [
'title' => $this->t('Revision: @date', [
Expand Down
2 changes: 1 addition & 1 deletion modules/next/tests/modules/next_tests/next_tests.info.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Next.js tests
description: Configures testing for Next.js
type: module
core_version_requirement: ^10 || ^11
apathak18 marked this conversation as resolved.
Show resolved Hide resolved
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