Problem/Motivation

Getting a bunch of notices and tracked it down to authcache_panels trying to render a mailchimp block.

Notice: Array to string conversion in drupal_render() (line 5978 of /includes/common.inc).

This is what the rendered array looks like:
https://gist.github.com/joelpittet/b1cc3e5386e363f212a7

Proposed resolution

Not sure if the correct solution is to check and use the array as a renderable array or mark the block as not cacheable in the hook. In this specific case it shouldn't be cached because it's a form block.

Remaining tasks

User interface changes

API changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joelpittet’s picture

Status: Active » Needs review

Possible solution?

From:

    $markup = !empty($content->content) ? $content->content : '';
    $element = array('#markup' => $markup);

To:

    $markup = !empty($content->content) ? $content->content : '';
    $element = (is_array($markup)) ? $markup : array('#markup' => $markup);
joelpittet’s picture

Here as a patch

znerol’s picture

Is the issue title correct? It does not seem to fit the summary.

According to your findings the content property of the $content parameter passed into hook_panels_pane_content_alter() can be a string or a render array. Is that correct?

In this specific case it shouldn't be cached because it's a form block.

It is not a requirement to load a block as an Ajax/ESI fragment only because it contains a form. At least as long as it does not contain any user-dependent default values (e.g. the email address of the currently logged in user).

znerol’s picture

znerol’s picture

Regrettably I was not able to reproduce this with a mailchimp subscription block in a panels pane. Do you use a special panels renderer class? Can you figure out what is calling hook_panels_pane_content_alter? (grep for panels_pane_content in your source tree, use a debugger or use the devel module and ddebug_backtrace()).

joelpittet’s picture

Title: Notice: Undefined index: settings in authcache_panels_pane_fragment_id » Notice: Array to string conversion in drupal_render()

Sorry I was sleeping on the title name, was trying to combine the two of the error message and where it was. Not sure how the word settings got in there...

joelpittet’s picture

It is not a requirement to load a block as an Ajax/ESI fragment only because it contains a form. At least as long as it does not contain any user-dependent default values (e.g. the email address of the currently logged in user).

That is good to know, this form is probably safe to cache then... I'm curious how I'd go about excluding that block though. The panel pane doesn't have authcache settings so I'm not sure why it's getting cached in the first place...
Does it default cache all panes?

joelpittet’s picture

re #5 I don't have any special panels renderer class, I am using panels everywhere... maybe that is special enough? Is the debug information enough in the issue summary gist? It is a backtrace.

joelpittet’s picture

According to your findings the content property of the $content parameter passed into hook_panels_pane_content_alter() can be a string or a render array. Is that correct?

Yes, here's where I've seen this before:
http://cgit.drupalcode.org/panels/tree/panels.module#n1266

znerol’s picture

Interesting. In this case it would be better to leave the rendering of $content->content up to panels-pane.tpl.php and instead just attach the personalization fragment to the existing render array.

joelpittet’s picture

Oh good call. I'll put that into production, thanks.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

Seems to be doing the job thus far;)

  • znerol committed 27aa50d on 7.x-2.x authored by joelpittet
    Issue #2429765 by joelpittet, znerol: Notice: Array to string conversion...
znerol’s picture

Status: Reviewed & tested by the community » Fixed

Thanks!

joelpittet’s picture

Thank you @znerol

Status: Fixed » Closed (fixed)

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