When trying to add a comment form to a panel, I get and EntityMalformedException error (see below) if and only if Panopoly Magic is enabled and tries to generate previews.

This is true across multiple installs for me on different server types and is true on a default Panopoly install at Pantheon.

If I disable panopoly_magic_pane_add_preview (i.e. set the variable to 0), the problem goes away, but the comment form has a Preview button and if I you click the Preview button, then I get the error upon generating the preview.

Error Message

An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /panels/ajax/editor/select-content/panel_context%3Anode_view%3A%3Anode_view_panel_context%3A%3A%3A%3A/top/comment
StatusText: Service unavailable (with message)
ResponseText: EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7721 of D:\Documents\htdocs\BBANZ\public_html\includes\common.inc).

Steps to Reproduce

  1. Set up a default install of Panopoly 1.2
  2. Enable the Comment module and make sure you have a content type with comments enabled
  3. Open the node view panel and add a variant: admin/structure/pages/edit/node_view
  4. Add Content
  5. Select Comment
  6. Wait for crash

Related issues for Panopoly
#1795474: AJAX error when editing panel page for content type (closed, cannot reproduce)
#1598990: Clicking on "Entities" on new pane screen gives AJAX error. (closed, fixed, but my error is happening in the new code)
#1829406: 500 error when attempting to add some content to panelizer (added a check that for the entity specifically because of problems dealing with comments)

Other related issues
#1778572: EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7562

What's Happening?

Essentially, the request eventually gets handed off to comment_reply which needs $context[0]->data->nid to be a valid node, but it's NULL.

The Magic function call is in panopoly_magic_preprocess_panels_add_content_modal (panopoly_magic.module line 1219):
ctools_content_render('comment_reply_form', 'comment_reply_form', array('anon_links' => FALSE), array(), array(), $context, NULL)
$context is an array of CTools Context objects.

Next ctools_content_render() in ctools/includes/content.inc line 280 calls
$content = $function($subtype, $conf, $args, $pane_context, $incoming_content);

Which has the values
$content = ctools_comment_reply_form_content_type_render('comment_reply_form', array('anon_links' => FALSE), array(), $pane_context, NULL)
Where $pane_context is an array of CTool context objects.

Finally ctools_comment_reply_form_content_type_render() (in ctools/plugins/content_types/comment/comment_reply_form.inc) assigns $node the value of $context[0]->data which is NULL.

So when the function calls comment_reply() and passes in a NULL $node variable, it crashes because comment_reply in core requires comments to have an associated node.

Proposed Fix

Uh... well the reason there's no patch is because I'm not sure how to go about this. I don't know whether comments are a special case. It seems that there are three cases, broadly speaking

  1. Attempt to view Preview and it crashes (the case I'm reporting)
  2. Attempt to Preview and it doesn't crash, but just responds with "No Preview" (this case is most obvious if you disable previews and get the "preview" link only.
  3. Successful preview

It seems like cases #1 and #2 need to be caught and stopped from trying to generate the preview or generating a preview link.

Workaround

If you disable previews at admin/panopoly/settings/panopoly_magic then at least you will be able to add those panes, though you will still get a crash when you click the Preview button.

Comments

dsnopek’s picture