diff --git a/modules/jsonapi_twig/src/TwigExtension.php b/modules/jsonapi_twig/src/TwigExtension.php index 7854cf5..6db3a3b 100644 --- a/modules/jsonapi_twig/src/TwigExtension.php +++ b/modules/jsonapi_twig/src/TwigExtension.php @@ -27,27 +27,7 @@ public function getFunctions() { } public function fetchFromJsonApi($resource, array $options = []) { - // @todo Do we really want to support this shortcut? - if ($resource instanceof EntityInterface) { - $resource = "/{$resource->getEntityTypeId()}/{$resource->bundle()}/{$resource->uuid()}"; - } - /** @var \Symfony\Component\HttpKernel\HttpKernelInterface $kernel */ - $kernel = \Drupal::service('http_kernel.basic'); - - $request = Request::create('/jsonapi/' . ltrim($resource, '/'), 'GET', $options + ['_format' => 'api_json']); - - // @todo Drop this workaround when https://www.drupal.org/node/2613044 is - // done - $previous_request = \Drupal::requestStack()->getCurrentRequest(); - - // @ Find a nicer implementation with maybe less layers involved. - $response = $kernel->handle($request, HttpKernelInterface::SUB_REQUEST, TRUE); - - \Drupal::requestStack()->push($previous_request); - - // @todo How to take into account cacheability metadata. - return Json::decode($response->getContent()); + return \Drupal::service('jsonapi.resource.to_json', ['resource' => $resource])->json(); } - }