Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
To reproduce:
- Add a disqus comment field to a content type, eg: article
- Go to the page to a new node, at eg: /node/add/article
- Enter any required fields, like title
- Click "Preview" to preview the node
The following error is generated:
Drupal\Core\Entity\EntityMalformedException: The "node" entity cannot have a URI as it does not have an ID in Drupal\Core\Entity\Entity->toUrl() (line 184 of core/lib/Drupal/Core/Entity/Entity.php). Drupal\disqus\Plugin\Field\FieldFormatter\DisqusFormatter->viewElements(Object, 'en') (Line: 85) Drupal\Core\Field\FormatterBase->view(Object, NULL) (Line: 264) Drupal\Core\Entity\Entity\EntityViewDisplay->buildMultiple(Array) (Line: 308) Drupal\Core\Entity\EntityViewBuilder->buildComponents(Array, Array, Array, 'default') (Line: 29) Drupal\node\NodeViewBuilder->buildComponents(Array, Array, Array, 'default') (Line: 251) Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array) (Line: 208) Drupal\Core\Entity\EntityViewBuilder->build(Array) call_user_func(Array, Array) (Line: 384) Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200) Drupal\Core\Render\Renderer->render(Array, ) (Line: 231) Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 577) Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 232) Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 122) Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 95) Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object) (Line: 116) Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 144) Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 62) Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 62) Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 53) Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 103) Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 82) Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 51) Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 55) Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23) Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 637) Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
The cause of this is Disqus trying to render comments when the entity has no ID (is not yet saved). I think the correct behavior would be to just render nothing in that case, or maybe some sort of placeholder "disqus comments would go here".
A workaround for now is to disable access to the field for unsaved entities:
function mysite_deploy_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
if ($field_definition->getType() == 'disqus_comment') {
$entity = $items->getEntity();
if (empty($entity->id())) {
return AccessResult::forbidden();
}
}
return AccessResult::neutral();
}
Comment | File | Size | Author |
---|---|---|---|
#13 | cannot_preview_a_new_node-2718557-13.patch | 1.1 KB | anton4uk |
Comments
Comment #2
omlx CreditAttribution: omlx commentedI face the same error:
2016/05/16 04:24:51 [error] 1337#1337: *73341 FastCGI sent in stderr: "PHP message: Uncaught PHP Exception Drupal\Core\Entity\EntityMalformedException: "The "node" entity cannot have a URI as it does not have an ID" at /var/www/drupal/core/lib/Drupal/Core/Entity/Entity.php line 179" while reading response header from upstream, client: 37.28.56.48, server: example.com, request: "GET /node/preview/b7685370-45f9-4d7d-91ae-33bcdff02a43/default HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "example.com", referrer: "http://example.com/node/add/story"
I disabled disqus in the node and preview works fine.
Comment #3
huzookaEasy-fix :)
Comment #4
vincenzodb CreditAttribution: vincenzodb as a volunteer commented#3 are ok, thx
Comment #5
slasher13Comment #6
csedax90 CreditAttribution: csedax90 commented#3 works like a charm
Comment #7
omlx CreditAttribution: omlx commentedThanks. The patch works great. Note, I have to apply this patch every time disqus get updated.
Comment #8
sudishth CreditAttribution: sudishth as a volunteer and commentedAfter change title of new node old comments disappear.
Comment #9
Cecilina CreditAttribution: Cecilina commentedFix the disquis identifier go override since index increased.
Comment #11
gaurav.kapoor CreditAttribution: gaurav.kapoor at Axelerant for Drupal India Association commentedComment #13
anton4uk CreditAttribution: anton4uk at Drupal Ukraine Community, Five Jars commentedNot only nodes can have Disqus.