contentacms / contenta_jsonapi

Contenta CMS, the decoupled Drupal
http://www.contentacms.org/
GNU General Public License v2.0
328 stars 104 forks source link

Node page view broken after JSON:API 8.x-2.4 update #357

Closed djvilione closed 5 years ago

djvilione commented 5 years ago

After updating JSON:API to 8.x-2.4, node views which display the JSON object are broken. I'm not sure if this is a Contenta, JSON:API, or JSON:API Extras issue, but can confirm that the site breaks in contenta_enhancements_node_view_alter when normalizing $entity. The on screen error is:

TypeError: Argument 1 passed to Drupal\jsonapi\JsonApiResource\ResourceObject::__construct() must implement interface Drupal\Core\Cache\CacheableDependencyInterface, instance of Drupal\jsonapi_extras\ResourceType\ConfigurableResourceType given, called in /var/www/site/web/modules/contrib/jsonapi_extras/src/EntityToJsonApi.php on line 99 in Drupal\jsonapi\JsonApiResource\ResourceObject->__construct() (line 79 of modules/contrib/jsonapi/src/JsonApiResource/ResourceObject.php).
Drupal\jsonapi\JsonApiResource\ResourceObject->__construct(Object, Object) (Line: 99)
Drupal\jsonapi_extras\EntityToJsonApi->normalize(Object) (Line: 371)
contenta_enhancements_node_view_alter(Array, Object, Object) (Line: 539)
Drupal\Core\Extension\ModuleHandler->alter('node_view', Array, Object, Object) (Line: 286)
Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array) (Line: 220)
Drupal\Core\Entity\EntityViewBuilder->build(Array)
call_user_func(Array, Array) (Line: 378)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 156)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 67)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 45)
Drupal\jsonapi\StackMiddleware\FormatSetter->handle(Object, 1, 1) (Line: 49)
Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Phillywonka commented 5 years ago

I can verify that downgrading the JSON:API Extras module to version 3.4 and the JSON:API module to version 2.3 solved this issue for me.

$ composer require drupal/jsonapi_extras=3.4 $ composer require drupal/jsonapi=2.3 $ drush cache:rebuild

e0ipso commented 5 years ago

This should now be fixed thanks to the latest release of JSON:API Extras, no downgrade necessary anymore.

e0ipso commented 5 years ago

Thanks for contributing to the issue queue!

walkerjam commented 5 years ago

@e0ipso I'm still seeing this same problem after a fresh install with:

If I insert a simple return statement as the first line in contenta_enhancements_node_view_alter, I have no issues. As far as I know, I don't have anything strange in my configuration (I've tried to keep it simple).

Would you consider re-opening this issue, or should I create a new one in one of the above projects?

e0ipso commented 5 years ago

Would you consider re-opening this issue, or should I create a new one in one of the above projects?

Absolutely. Can you share the error messages here?

BluAmpersand commented 5 years ago

Same here: The website encountered an unexpected error. Please try again later.

Message | LogicException: Render context is empty, because render() was called outside of a renderRoot() or renderPlain() call. Use renderPlain()/renderRoot() or #lazy_builder/#pre_render instead. in Drupal\Core\Render\Renderer->doRender() (line 241 of /home/website/website.com/contentacms/web/core/lib/Drupal/Core/Render/Renderer.php).

Know in the past had to deal with contenta_enhancements... may have to do with being in core now - never changed contenta_enhancements. ALSO see, DO: jsonapi_extras/issues/3045087 & jsonapi_extras/issues/3044925 (and /schemata/issues/3045194 & schemata/issues/3044788 Have no Idea why got posted there? Can see it related to contenta_enhancements) all seem related. But think the fix is needed in contenta_enhancements... it is also the longest non upgraded part.

I've been upgrading the same Contenta site for 6-7 months... Actually only have contenta_enhancements module in the database code, as I don't see it in /contrib module folder anymore! -so don't know when it was removed from the contenta config.json... I've just used 'composer update' and lots of reading the tea-leaves on fixes to keep it up and running all this time from the original install.

Good stuff you guys been doing. Looking forward to meet in Seattle.

djvilione commented 5 years ago

In chatting about this on the Slack channel, I believe it's a Schemata issue at this point.

e0ipso commented 5 years ago

Thanks for the patience here, there are many moving pieces to this. At the moment https://www.drupal.org/project/jsonapi_extras/issues/3049221 is a known issue that may cause this.

e0ipso commented 5 years ago

Please see: https://github.com/contentacms/contenta_jsonapi/pull/361