Hello,
here's the output I've got of the "examples/theming_example" page :
Theming Example
1ome examples of pages and forms that are run through theme functions.
1a href="/examples/theming_example/theming_example_list_page">Simple page with a list
1a href="/examples/theming_example/theming_example_select_form">Simple form 1
1a href="/examples/theming_example/theming_example_text_form">Simple form 2
And if I reload the page, I got these warnings 4 times :
Warning : Invalid argument supplied for foreach() in element_children() (line 6300 in .../includes/common.inc).
Warning : Illegal string offset '#children' in drupal_render() (line 5767 in .../includes/common.inc).
Warning : Illegal string offset '#children' in drupal_render() (line 5777 in .../includes/common.inc).
Warning : Illegal string offset '#children' in drupal_render() (line 5815 in .../includes/common.inc).
Warning : Illegal string offset '#printed' in drupal_render() (line 5822 in .../includes/common.inc).Didn't find where the problem starts. I first though it was a problem with the l() or t() function but even if I put some simple string in the $content array of the theming_example_page() function, it returns this : "1y string" instead of "my string"...
And by the way, thanks for the examples !
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | Screen Shot 2017-01-09 at 6.37.47 PM.png | 63.38 KB | manav |
| #18 | Screen Shot 2017-01-09 at 6.37.40 PM.png | 63.94 KB | manav |
| #18 | Screen Shot 2017-01-09 at 6.37.15 PM.png | 41.58 KB | manav |
| #18 | Screen Shot 2017-01-09 at 6.37.03 PM.png | 66.3 KB | manav |
| #16 | theming_example_page-1764884-16.patch | 3.99 KB | navneet0693 |
Comments
Comment #1
amitgoyal commentedhi anou - i tried replicating this issue on my system but couldn't replicate this. i am using drupal 7.15 and latest code of examples module.
can you please provide more information on how to replicate this issue and tell me which versions you are using for drupal and module?
Comment #2
rfayI note that it seems to work on the Drupalexamples.info site as well, http://d7.drupalexamples.info/examples/theming_example
Marking "needs more info"
Thanks for supporting this, @amitgoyal!
Comment #3
anouHello,
Yep seems to work well on the drupalexamples.info site ;-).
I really don't know how to tell you how to replicate this issue.
I'm using Drupal 7.15 and I updated to the last version of example module (I saw today that there was one...) and I still got my bug :-(
Here's a screenshot if it might help...
Thanks for your attention.
Comment #4
amitgoyal commented@anou - Looks like screenshot is incomplete. I couldn't see any warnings there as per your initial comment.
I also tested this in Drupal 7.15 and latest version of Examples module but there is no such issue.
Comment #5
Jef-DS commentedI have noticed the same behavior that was mentioned in this issue (Invalid argument supplied, line 6300 in common.inc). I don't know much about the Drupal theming system (yet ;-) ). But I have stepped through the module with a debugger. And I noticed that the problem could be due to the function theming_example_page() (in theming_example.module).
I was wondering if #theme_wrappers is the right property name in this case. When I change it into #theme:
the errors disappear.
As I said, I don't know much about theming. And I don't know if this is the right solution to this problem. But stepping through the code with a debugger showed me that $content[0] to $content[3] where not themed by 'theming_example_content_array'. But those lines where used as $elements in line 6300 in common.inc
and that was the reason for the warning. (in my case)
I also don't know why the example does not work for me(Drupal 7.15 and PHP 5.4) and @anou. And why it does work on http://d7.drupalexamples.info/examples/theming_example .
So as you can see I am at loss how this works. And consequently I really would like to know what is wrong here and how it can be solved. (and also if #theme should be used instead of #theme_wrappers)
Comment #6
mile23I'm not seeing the errors as in the original post, so I'm going to hijack this a little. :-)
It seems to me that the big problem with the theming example is that theming_example_page() doesn't output a structured themeable array. That is, if you don't set #theme and/or #theme_wrapper functions, Drupal has no idea what to do with this content.
So: theming_example_page() should really just inline theme_theming_example_content_array(), with proper #renderkeys instead of HTML. Since theming_example_list_page() does this, it's unclear what theming_example_page() is trying to demonstrate.
Anyone have any idea?
Comment #7
sprice commentedI can't remember exactly how to fix it, but the problem is that drupal_render() works well for php 5.3 but breaks a bit in 5.4. I think that it's something about the array recursion in the function. But this is a common problem across most modules.
If I remember where the patch is to fix it, then I'll post. Ultimately, it isn't a problem with this module but a problem with the way that core interacts with php 5.4.
Comment #8
sprice commentedActually, everywhere that I read just says to turn off strict error reporting on php 5.4. Drupal 7.23 included a fix, and as far as I can tell, you just need to do something along the lines of just sending drupal_render a variable rather than the results of a function. Here's an example:
http://drupalcode.org/project/node_accessibility.git/blobdiff/98fab6350b...
Maybe that helps.
Comment #9
Alienpruts commentedJust to let everyone know I still had this error on my setup.
Indeed, when stepping through the code with a debugger, I noticed something odd :
When examening the $content variable all seems well, all data that should be there is there( ie. l-function and t-function did their magic and supplied the correct data).
However, when inspecting the theme_theming_example_content_array function (as defined in $content['#theme_wrappers'], and more specifically the $variables variable, something strange happened :
When inspecting $variables the $variables['element'] children suddenly have had their contents changed, thus leading to the fault at hand.
I've added two screenshots to illustrate my point.
Curiously, the solution suggested at https://drupal.org/node/1764884#comment-6478070 works : if you change the $content['#theme_wrappers'] to $content['#theme'] everything works nicely, even the errors disappear completely.
My setup : PHP 5.5.3-1ubuntu2.3 and Drupal 7.28.
========================================================
EDIT : for those who don't know the difference between #theme_wrappers and #theme :
========================================================
#theme A single theme hook which will take full responsibility for rendering this array element, including its children. It has predetermined knowledge of the structure of the element. Note: #theme in Drupal 7 and #theme in Drupal 6 are not really related. If you just stop thinking about Drupal 6 here, you will have an easier time.
Basically, the '#theme' = 'function_name' calls theme_function_name(), and other array values of the form '#var_name' = $value in the same array are passed as arguments to the theme function.
There is a list of all the default theme hooks at http://api.drupal.org/api/drupal/modules--system--theme.api.php/group/th...
#theme_wrappers An array of theme hooks which will get the chance to add to the rendering after children have been rendered and placed into #children. This is typically used to add HTML wrappers around rendered children, and is commonly used when the children are being rendered recursively using their own theming information. It is rare to use it with #theme.
This explains why #theme works, but still doesn't explain why #theme_wrappers doesn't work!
Comment #10
zephybear commentedIn render_example.module you can see the format it has to be in to be rendered correctly.
But the array as it is in theming_example_content_array has a slightly different output
The strings in array [0] to [3] seems to need to be put in a sub-array and cannot be at the same level as #theme_wrappers from what I see. That seems to be why #theme works. All the text is in the same array.
But if I change the array, then the foreach loop doesn't work anymore and I'm sorry but I'm a bit new to Drupal and PHP so I'm not sure what to do next yet.
Comment #11
dustise commentedAdd the following line into the function theming_example_page() :
$content['#children'] = array();
Comment #12
lokapujyaShould either initialize #children to an array or build the render array differently.
Comment #13
lokapujyaThe existing code fails tests in later versions of PHP.
Comment #14
navneet0693 commentedLong story short:
After hours of pulling hairs and spamming IRC channels of drupal, finally I found that _culprit_ in common.inc in function
drupal_render(&$elements)at line number: 6039. The function expects$elementasarray()but it is passed as string, and there is no check for$elementto be string. And at line number: 6040, it tries to add index#childrenlike this$elements['#children'] = ' ';and fails dramatically, resulting in errors also in removal of first character and this line$elements['#printed'] = TRUE;was responsible for converting first character to 1.Earlier I thought it's a core issue on drupal 7.53, but i guess our implementation was not correct. As per my understanding to render an array we follow this process: https://www.drupal.org/docs/7/api/render-arrays/render-arrays-overview
Please correct me if my understanding is wrong.
Comment #15
lokapujyaDidn't look too closely, but does this need to change?
A couple of comments exceeding 80 chars.
Comment #16
navneet0693 commentedComment #17
manav commentedComment #18
manav commentedThis patch works fine for me. After applied this patch all 3 link working fine without any error. Attaching the screen-shot for the same.
Drupal version: 7.x
Php ver: 5.6
Mysql ver: 5.5
Comment #20
mile23Fixed some coding standards stuff in and near the patches.
Thanks for finally putting this one to bed. :-)