-
Notifications
You must be signed in to change notification settings - Fork 2
feat: drupal 10 compatibility update #135
Changes from all commits
e8fb662
933037b
65b3bf1
1f57091
5f7e20a
367c0db
49f3421
32e24ca
df2a3bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updating Symfony response and request events to new classes |
||
use Symfony\Component\HttpKernel\Event\ResponseEvent; | ||
use Symfony\Component\HttpKernel\KernelEvents; | ||
|
||
/** | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updating Symfony response and request events to new classes |
||
if (!$this->jsonApiEnabled) { | ||
return; | ||
} | ||
|
@@ -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'] ?? []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In symfony 6, the InputBag::get(), no longer accepts arrays as default values There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used to use query->get so much in Symfony work, I have no idea why the moved it towards the fetch all as an array and get the element (probably a PHP 8 thing truth be told) |
||
if ($site_id) { | ||
$context = $response->getCacheableMetadata()->getCacheContexts(); | ||
$context = Cache::mergeContexts($context, ['url.query_args:site']); | ||
|
@@ -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'] ?? []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In symfony 6, the InputBag::get(), no longer accepts arrays as default values |
||
$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' => [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this has been changed to tackle this issue - https://digital-vic.atlassian.net/browse/SRM-1167 |
||
|
||
// Remove the site prefix from path alias when responding from | ||
// JSONAPI entity resource with site parameter. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Breaking change, good job!