Skip to content
This repository was archived by the owner on Apr 17, 2024. It is now read-only.

Commit 6f07a5e

Browse files
authored
fix: node page view broken after JSON:API 8.x-2.4 update (#361)
* fix: execute entity to JSON:API in render context * fix: upgrade JSON:API dependencies
1 parent 8499d97 commit 6f07a5e

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
"drupal/entity_browser": "^2.0@alpha",
5555
"drupal/image_widget_crop": "^2.1",
5656
"drupal/inline_entity_form": "^1.0@beta",
57-
"drupal/jsonapi": "^2.1",
58-
"drupal/jsonapi_extras": "^3.3",
57+
"drupal/jsonapi": "^2.4",
58+
"drupal/jsonapi_extras": "^3.6",
5959
"drupal/jsonrpc": "^1.0@beta",
6060
"drupal/material_admin": "^1.0@alpha",
6161
"drupal/media_entity_browser": "^2.0@alpha",

modules/contenta_enhancements/contenta_enhancements.module

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

33
use Drupal\Core\Entity\EntityTypeInterface;
4+
use Drupal\Core\Render\RenderContext;
5+
use Drupal\Core\Render\Renderer;
46
use Drupal\Core\Url;
57
use Drupal\Core\Form\FormStateInterface;
68
use Drupal\node\NodeInterface;
@@ -366,9 +368,14 @@ function contenta_enhancements_node_view_alter(array &$build, NodeInterface $ent
366368
if ($entity->bundle() === 'page') {
367369
return;
368370
}
371+
$renderer = \Drupal::service('renderer');
372+
assert($renderer instanceof Renderer);
369373
// Retrieve JSON API representation of this node.
370-
$entity_to_jsonapi = \Drupal::service('jsonapi_extras.entity.to_jsonapi');
371-
$normalized = $entity_to_jsonapi->normalize($entity);
374+
$render_context = new RenderContext();
375+
$normalized = $renderer->executeInRenderContext($render_context, function () use ($entity) {
376+
$entity_to_jsonapi = \Drupal::service('jsonapi_extras.entity.to_jsonapi');
377+
return $entity_to_jsonapi->normalize($entity);
378+
});
372379

373380
// Generate markup.
374381
$flags = JSON_HEX_TAG

0 commit comments

Comments
 (0)