To reproduce:

  1. Add a disqus comment field to a content type, eg: article
  2. Go to the page to a new node, at eg: /node/add/article
  3. Enter any required fields, like title
  4. 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();
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vasi created an issue. See original summary.

omlx’s picture

I 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.

huzooka’s picture

Version: 8.x-1.0-beta2 » 8.x-1.x-dev
Status: Active » Needs review
FileSize
1.41 KB

Easy-fix :)

vincenzodb’s picture

#3 are ok, thx

slasher13’s picture

Status: Needs review » Reviewed & tested by the community
csedax90’s picture

#3 works like a charm

omlx’s picture

Thanks. The patch works great. Note, I have to apply this patch every time disqus get updated.

sudishth’s picture

Status: Reviewed & tested by the community » Needs work

After change title of new node old comments disappear.

Cecilina’s picture

Fix the disquis identifier go override since index increased.

  • Cecilina authored f904720 on 8.x-1.x
    Issue #2718557 by huzooka, Cecilina: Can't preview a new node
    
gaurav.kapoor’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

anton4uk’s picture

Not only nodes can have Disqus.