Closed (outdated)
Project:
Drupal core
Version:
7.x-dev
Component:
render system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
29 Aug 2015 at 00:57 UTC
Updated:
31 Aug 2015 at 18:48 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
ttread commentedPatch that fixes this problem. It prevents drupal_render from processing non-arrays.
Comment #3
cilefen commentedI am just curious. How is a non-array arriving from your module_invoke in the first place?
Comment #4
cilefen commentedComment #5
cilefen commentedComment #6
ttread commentedTraced this in the debugger. The problem occurs on the call to print render(). In my module's hook_block_view, $block['subject'] is set to a string as per the API documentation, with the render array in $block['content']. Print render() calls drupal_render(), which on line 5977 sets the variable $children to ['subject', 'content']. When drupal_render calls itself recursively on its children on line 5994, the first child, the string subject, is passed in where it's expecting an array.
I don't think this problem has anything to do with my module code, and suspect it could be affecting other sites, unless I've overlooked something.
Comment #7
cilefen commentedCould we see your implementation of hook_block_view?
Comment #8
ttread commentedI just realized what I did wrong, in the template I used print render($my_element) when I should have used print render($my_element['content']). So this is my error.
Nonetheless, this patch #2 could be useful to prevent problems when others make this mistake.
Comment #9
cilefen commentedArguably you would want to throw an exception here.
It's funny, on a Drupal 8 issue I asked @joelpittet a deeper question: "How do you know if an array you have been passed is a render array?" It is not trivial.