Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
feat: drupal 10 compatibility update (#135)
Browse files Browse the repository at this point in the history
* feat: Drupal 10 update.

---------

Co-authored-by: Md Nadim Hossain <[email protected]>
  • Loading branch information
vincent-gao and MdNadimHossain authored Nov 16, 2023
1 parent 034db50 commit 23c1939
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 789 deletions.
16 changes: 11 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@
"type": "drupal-module",
"license": "GPL-2.0-or-later",
"require": {
"dpc-sdp/tide_core": "^3.2.5",
"dpc-sdp/tide_media": "^3.0.8",
"drupal/create_menus_permission": "^1.0",
"dpc-sdp/tide_core": "^4.0.0",
"dpc-sdp/tide_media": "^4.0.0",
"drupal/create_menus_permission": "dev-drupal_10_compatibility",
"drupal/key_value_field": "^1.3"
},
"suggest": {
"dpc-sdp/tide_api:^3.0.0": "Allows to use Drupal in headless mode"
"dpc-sdp/tide_api:^4.0.0": "Allows to use Drupal in headless mode"
},
"repositories": {
"drupal": {
"type": "composer",
"url": "https://packages.drupal.org/8"
"url": "https://packages.drupal.org/10",
"exclude": ["drupal/create_menus_permission"]
},
"drupal/create_menus_permission": {
"type": "vcs",
"no-api": true,
"url": "https://github.com/dpc-sdp/create_menus_permission.git"
}
},
"extra": {
Expand Down
2 changes: 1 addition & 1 deletion modules/tide_site_preview/tide_site_preview.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: 'Tide Site - Preview links'
description: Provides frontend preview links for content managed with Tide Site.
type: module
package: Tide
core_version_requirement: ^8.9 || ^9
core_version_requirement: ^9 || ^10
dependencies:
- dpc-sdp:tide_site
- dpc-sdp:tide_api
Expand Down
28 changes: 0 additions & 28 deletions modules/tide_site_preview/tide_site_preview.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* Tide Site install file.
*/

use Drupal\block\Entity\Block;
use Drupal\user\Entity\Role;

/**
Expand All @@ -22,30 +21,3 @@ function tide_site_preview_install() {
}
}
}

/**
* Remove block.block.seven_tide_site_preview_links.
*/
function tide_site_preview_update_8001() {
$block = Block::load('seven_tide_site_preview_links');
if ($block !== NULL) {
$block->delete();
}
}

/**
* Install block.block.claro_tide_site_preview_links.
*/
function tide_site_preview_update_8002() {
\Drupal::moduleHandler()->loadInclude('tide_core', 'inc', 'includes/helpers');
$config_location = [\Drupal::service('extension.list.module')->getPath('tide_site_preview') . '/config/optional'];
$storage = \Drupal::entityTypeManager()->getStorage('block');
$id = 'claro_tide_site_preview_links';
$config_entity = $storage->load($id);
if ($config_entity !== NULL) {
$storage->delete([$config_entity]);
}
$config_read = _tide_read_config('block.block.claro_tide_site_preview_links', $config_location, FALSE);
$new_config_entity = $storage->createFromStorageRecord($config_read);
$new_config_entity->save();
}
17 changes: 0 additions & 17 deletions modules/tide_site_simple_sitemap/tide_site_simple_sitemap.install
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ function tide_site_simple_sitemap_install($is_syncing) {
_update_settings();
}

/**
* Updates bundle settings.
*/
function tide_site_simple_sitemap_update_8008(&$sandbox) {
_update_settings();
}

/**
* Update for sitemap 4.x.
*/
Expand Down Expand Up @@ -83,13 +76,3 @@ function _update_settings() {
}
}
}

/**
* Removes simple_sitemap_site table.
*/
function tide_site_simple_sitemap_update_8009() {
$hasTable = \Drupal::database()->schema()->tableExists('simple_sitemap_site');
if ($hasTable === TRUE) {
\Drupal::database()->schema()->dropTable('simple_sitemap_site');
}
}
22 changes: 11 additions & 11 deletions src/EventSubscriber/TideSiteRequestEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableResponseInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Routing\RouteObjectInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;
use Drupal\jsonapi\Routing\Routes;
use Drupal\jsonapi_extras\ResourceType\ConfigurableResourceType;
use Drupal\tide_site\TideSiteFields;
use Drupal\tide_site\TideSiteHelper;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

/**
Expand Down Expand Up @@ -86,13 +86,13 @@ public static function getSubscribedEvents() {
/**
* Add Site filter to the request of JSON API controller.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* @param \Symfony\Component\HttpKernel\Event\RequestEvent $event
* The event.
*
* @see \Symfony\Component\HttpKernel\HttpKernel::handleRaw()
* @see \Drupal\jsonapi\Controller\RequestHandler::handle()
*/
public function onRequestAddSiteFilter(GetResponseEvent $event) {
public function onRequestAddSiteFilter(RequestEvent $event) {
if (!$this->jsonApiEnabled) {
return;
}
Expand Down Expand Up @@ -214,16 +214,16 @@ public function onRequestAddSiteFilter(GetResponseEvent $event) {
/**
* Add Site to cache context and tags of JSON API response.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event
* The event object.
*/
public function onResponseAddSiteFilterCacheContext(FilterResponseEvent $event) {
public function onResponseAddSiteFilterCacheContext(ResponseEvent $event) {
$response = $event->getResponse();
if (!$response instanceof CacheableResponseInterface) {
return;
}

$site_id = $event->getRequest()->query->get('site');
$site_id = $event->getRequest()->query->all()['site'] ?? [];
if ($site_id) {
$context = $response->getCacheableMetadata()->getCacheContexts();
$context = Cache::mergeContexts($context, ['url.query_args:site']);
Expand All @@ -246,22 +246,22 @@ public function onResponseAddSiteFilterCacheContext(FilterResponseEvent $event)
* The Resource type.
*/
protected function setSiteFilterToJsonApi(Request $request, array $site_filter, ConfigurableResourceType $resource_type) {
$filter = $request->query->get('filter', []);
$filter = $request->query->all()['filter'] ?? [];
$filter['site'] = $site_filter;
$request->query->set('filter', $filter);
}

/**
* Create a JSON Response for error message.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* @param \Symfony\Component\HttpKernel\Event\RequestEvent $event
* The event.
* @param string $error_message
* The error message.
* @param int $code
* The error code, default to 400.
*/
protected function setEventErrorResponse(GetResponseEvent $event, $error_message, $code = Response::HTTP_BAD_REQUEST) {
protected function setEventErrorResponse(RequestEvent $event, $error_message, $code = Response::HTTP_BAD_REQUEST) {
$json_response = [
'links' => [
'self' => [
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/Linkit/Substitution/Canonical.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static function create(ContainerInterface $container, array $configuratio
*/
public function getUrl(EntityInterface $entity) {
/** @var \Drupal\Core\GeneratedUrl $url */
$url = parent::getUrl($entity);
$url = parent::getUrl($entity)->toString(TRUE);

// Remove the site prefix from path alias when responding from
// JSONAPI entity resource with site parameter.
Expand Down
2 changes: 1 addition & 1 deletion tide_site.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: 'Tide site'
description: 'Functionality to allow post content to multiple sites and sections.'
type: module
package: Tide
core_version_requirement: ^8.9 || ^9
core_version_requirement: ^9.5 || ^10
dependencies:
- drupal:field
- drupal:field_ui
Expand Down
Loading

0 comments on commit 23c1939

Please sign in to comment.