Symptoms

Watchdog warnings with:
Location: /features/ajaxcallback/*
Referrer: /admin/structure/features/create
Message:

Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (line 1559 of ..../includes/bootstrap.inc)

Steps to reproduce

Make a call to drupal_get_title() during the Features AJAX request, e.g. using the statistics module:

Machine: wodby/docker4drupal running PHP 7.3
- Install Drupal 7 and Drush 8
- drush ws —tail
- drush en -y statistics
- drush vset statistics_enable_access_log 1
- drush en -y features
- Visit admin/structure/features/create
- Click the link ’Text formats’ then ‘Plain text’

Watchdog:
21 20/Oct 08:20 warning php Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (line 1856 of /var/www/html/web/includes/bootstrap.inc).

Technical explanation

features_menu() registers a router item at 'features/ajaxcallback/%' with 'title callback' => 'features_get_feature_components'.
The features_get_feature_components() callback returns an array instead of a string.
An ajax callback should not have a title callback, anyway.

Solution

In this issue we register a fixed value for the title, instead of a title callback.

Follow-up

Perhaps the page callback should be changed to call drupal_exit(), or a delivery callback 'ajax_deliver' should be used.

CommentFileSizeAuthor
#8 2006432.patch722 bytesDavid Sparks
#7 3172365.patch619 bytesDavid Sparks
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hefox’s picture

Status: Active » Postponed

Why was ctools marked as component? nothing if this bug report indicates it's ctools intergration specific

On that line that is triggerring the warning,

if (is_array($that_variable) {
  some sort of print statement debug_backtrace(); 
}
hefox’s picture

Status: Postponed » Postponed (maintainer needs more info)
dojorob76’s picture

I am getting this same message (repeatedly) in my dblog after creating new features. I actually turned the ctools dependency off for the last run to see if that had anything to do with it, but that did not change anything. I still got 29 lines of this error for one feature.

I tried creating a feature with no Field Instances (where the bulk of the html was in description fields) as well, but the warnings persist.

Location: http://~mysite~.com/features/ajaxcallback/*
Referrer: http://~mysite~.com/admin/structure/features/create
Message: Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (line 1565 of /home/~path~/~to~/~mysite~/includes/bootstrap.inc).
Severity: Warning

The features appear to be created correctly. I can generate and/or download them, but with all these warnings, I would hesitate to use them anywhere.

Using Features 7.x-2.0-rc4 with Drupal 7.23 running on PHP 5.3.27

mpotter’s picture

Please see the suggestion in #1 about using debug_backtrace. Showing an error from Drupal core (bootstrap.inc) doesn't help track down this problem. We need to see where in Features this is being called. I was not able to reproduce it in my test sites.

makokis’s picture

same issue here

Mensaje de error
Warning: htmlspecialchars() expects parameter 1 to be string, array given en check_plain() (línea 1565 de /home5/teleinfo/public_html/includes/bootstrap.inc).

any idea to solve this?

Chris Charlton’s picture

Issue summary: View changes

my dblog is filled with these too.

David Sparks’s picture

FileSize
619 bytes

This problem is caused by the Features AJAX callback menu item having a title callback that doesn't always (/ever?) return a string.

The callback used is features_get_feature_components(). I have no idea why we need a title callback rather just a fixed menu item title - presumably not an accident. However, after switching from a title callback to a fixed title I didn't seem to have any problems with AJAX functionality.

Patch attached.

David Sparks’s picture

FileSize
722 bytes

Wrong patch! Try this one.

donquixote’s picture

Nice catch @David Sparks!
I think your patch makes sense.

Could you add steps to reproduce in the issue summary? I want to be able to compare before/after, before I commit this.

David Sparks’s picture

Issue summary: View changes

Sorry for the delay - done now.

donquixote’s picture

Title: Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() » Router item 'features/ajaxcallback/%' has bogus title callback.
Issue summary: View changes
donquixote’s picture

It is funny, it was indeed statistics module that caused the drupal_get_title().

donquixote’s picture

I checked other ajax router items like 'views/ajax' and 'system/ajax'.
I think the 'title' is not strictly necessary, but those also have it, so I think we are on the safe side by setting a fixed title.
(the default title callback is t(), so it will be translated, but that's ok)

Other ajax callbacks also use 'delivery callback', but we can do this later.

donquixote’s picture

Status: Postponed (maintainer needs more info) » Fixed

Nice job @David Sparks, thank you!

donquixote’s picture

If anyone else still sees this message for some unrelated reason, please get a backtrace and open a new issue.

Status: Fixed » Closed (fixed)

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