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.
Comment | File | Size | Author |
---|---|---|---|
#8 | 2006432.patch | 722 bytes | David Sparks |
Comments
Comment #1
hefox CreditAttribution: hefox commentedWhy was ctools marked as component? nothing if this bug report indicates it's ctools intergration specific
On that line that is triggerring the warning,
Comment #2
hefox CreditAttribution: hefox commentedComment #3
dojorob76 CreditAttribution: dojorob76 commentedI 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
Comment #4
mpotter CreditAttribution: mpotter commentedPlease 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.
Comment #5
makokis CreditAttribution: makokis commentedsame 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?
Comment #6
Chris Charltonmy dblog is filled with these too.
Comment #7
David Sparks CreditAttribution: David Sparks as a volunteer commentedThis 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.
Comment #8
David Sparks CreditAttribution: David Sparks as a volunteer commentedWrong patch! Try this one.
Comment #9
donquixote CreditAttribution: donquixote commentedNice 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.
Comment #10
David Sparks CreditAttribution: David Sparks as a volunteer commentedSorry for the delay - done now.
Comment #11
donquixote CreditAttribution: donquixote commentedComment #12
donquixote CreditAttribution: donquixote commentedIt is funny, it was indeed statistics module that caused the drupal_get_title().
Comment #13
donquixote CreditAttribution: donquixote commentedI 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.
Comment #15
donquixote CreditAttribution: donquixote commentedNice job @David Sparks, thank you!
Comment #16
donquixote CreditAttribution: donquixote commentedIf anyone else still sees this message for some unrelated reason, please get a backtrace and open a new issue.