Hi,
in 7.33 ( https://www.drupal.org/drupal-7.33-release-notes ) was added a "theme_hook_original" variable to templates and theme functions.

Added a "theme_hook_original" variable to templates and theme functions and an optional sitewide theme debug mode, to provide contextual information in the page's HTML to theme developers. The theme debug mode is based on the one used with Twig in Drupal 8 and can be accessed by setting the "theme_debug" variable to TRUE (API addition).

When using DS to theme search results in Apachesolr, starting from Drupal 7.33 (7.34 affected as well) it starts throwing warnings like:

Warning: Invalid argument supplied for foreach() in element_children() (line 6481 of /includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 5933 of /includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 5943 of /includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 5981 of /includes/common.inc).
Warning: Illegal string offset '#printed' in drupal_render() (line 5988 of /includes/common.inc).

In theme.inc, line 1094, there is
$variables['theme_hook_original'] = $theme_hook_original;
and this adds string "ds_search_page" (name of hook) on $build array which later, when sent to drupal_render, doesn't know what to do with that string as it doesn't have any children defined that render function uses to display output.

Now, since 7.33 added this, a lot of modules complain about it, and are handling on their side instead in core. That variable can be unset and ds will work just fine, but there sohuld be much better solution. I am not 100% sure if this should be reported to core as well, but if module maintainers decided to go with fixing on their side until core doesn't react, DS might as well "patch" this up too.

Here are some issues related to new variable added:
https://www.drupal.org/node/2371907
https://www.drupal.org/node/2379771

Update: removed DS and it no errors appeared anymore. Probably DS related issue regarding newly added variable?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

milovan’s picture

Issue summary: View changes
crutch’s picture

I'm experiencing this issue with DS search without solr. Looks like it may be here that needs altering?

sites\all\modules\ds\ds.module

stephane-v’s picture

I also experience this issue with DS.
I just added 2 lines in begining of the theme_ds_search_page function to fix this :

function theme_ds_search_page($build) {
  // fix for Drupal 7.33+
  if(isset($build['theme_hook_original'])) {
    unset($build['theme_hook_original']);
  }
  // Check on empty search results.
  if (empty($build['search_results'])) {

    // Alter the title and extra variables.
    if (!empty($build['search_title'])) {
      $build['search_title']['#markup'] = '<h2>' . t('Your search yielded no results') . '</h2>';
      unset($build['search_extra']);
    }

    $build['search_empty'] = array('#markup' => search_help('search#noresults', drupal_help_arg()));
  }

  $build['search_results']['#sorted'] = TRUE;

  return $build;
}
jover’s picture

You don't need to patch the Display Suite module to solve this problem.
You can easily remove the "theme_hook_original" variable in a custom theme override and still using the theme_ds_search_page()-function like so:

function MY_THEME_ds_search_page($build) {
  // Fix for Drupal 7.33+
  if (isset($build['theme_hook_original'])) {
    unset($build['theme_hook_original']);
  }

  return theme_ds_search_page($build);
}
crutch’s picture

Thanks jover works perfectly. Just now got back to this.

I added and replaced MYTHEME with my theme name and added to template.php located in my theme folder. Re-save theme by just visiting it and clicking save, then flush cache and all is well.

/**
 * Fix Display Suite warnings that never end.
 */

function MYTHEME_ds_search_page($build) {
  // Fix for Drupal 7.33+
  if (isset($build['theme_hook_original'])) {
    unset($build['theme_hook_original']);
  }
  return theme_ds_search_page($build);
}
milovan’s picture

I confirm this works and is better solution than patching DS. Thanks jover!

sanette’s picture

The jover technique works for me too; thanks!
however there is still a warning when the search produces no result:

Warning : uasort() expects parameter 1 to be array, null given dans node_view_multiple()

webservant316’s picture

#4/5 worked for me. hey what is the future of this issue? I just pasted the fix into 6 theme template files. however, I looked forward to removing that code when I can.

aspilicious’s picture

I think there a deeper underlaying issues with the search templates.
Sadly enough, I *never* use this functionality myself so it's hard for me to find the time to properly fix this.

It's possible I'm going to apply the bandaid from #3 for now.

webservant316’s picture

I reversed my use of #4/5 so that I did not need to maintain the fix in all my template files. Instead I patched ds directly with #3 and it works fine.

d1m5n’s picture

Patch #3 works,

Added:
// fix for Drupal 7.33+
if(isset($build['theme_hook_original'])) {
unset($build['theme_hook_original']);
}

@line 58 in ds/modules/ds_search/ds_search.module

Is this going to be solved in the next version?
If not, i need to repatch this when we update DS.

Daemon_Byte’s picture

#3 worked for me.

Daemon_Byte’s picture

In the hopes it will speed things up I have rolled #3 into a git patch for the latest development version.

Daemon_Byte’s picture

Status: Active » Patch (to be ported)
webservant316’s picture

hey this didn't get committed to ds-7.x-2.8. I am reapplying patch #3 now. Hope this gets fixed.

aspilicious’s picture

Status: Patch (to be ported) » Fixed

Added the bandaid, forgot this patch when making the 2.9 so I made a 2.10 for all of you affected by this one. (which will be available in a few minutes)

Status: Fixed » Closed (fixed)

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

raj45’s picture

Thanks @aspilicious, upgrading to 2.11 makes the warnings go away.

gchalker@princeton.edu’s picture

Thanks Cruch, had the same error with my search function. Your script in the theme.php file solved the issue!

Regards, gg

capysara’s picture

I'm still using version 1.9. I was getting these error messages, but the fix in #4/5 worked for me. Thanks!