Problem/Motivation
Warning: Array to string conversion in panels_cache_object->cache() (line 158 of /mnt/www/html/jnjnab4d1dev8/docroot/profiles/jjbos/modules/contrib/panels/includes/plugins.inc).
Steps to reproduce
- Open the main application page.
- Log in as admin.
- Go to /admin/structure/pages.
- Click on the 'Edit' link in a row of any existing panel page.
- Click on the 'Content' link.
- Click on the gear icon near one of the blocks.
- Click on Caching->Change.
- Click on the 'Simple Cache' radio button and click 'Next'.
- Select '15 sec' in Lifetime and click the "Save' button.
- Click on the 'Update and Save' button.
- Go to /admin/config/development/performance.
- Click on the 'Clear all caches' button.
- Go to a page from step 4.
Proposed resolution
Here is a commit - https://git.drupalcode.org/project/panels/-/commit/13c4dc1492a74e3dd82c3...
introduced the issue ( 11 year ago, during migration from Drupal 6 to Drupal 7, possibly)
- $this->head = str_replace($this->head, '', drupal_set_html_head());
+ $this->head = str_replace($this->head, '', drupal_add_html_head());
The first problem: drupal_set_html_head always returns a string, and str_replace makes sense.
drupal_add_html_head always returns an array, and the sense is not as clear as before.
Second problem in function restore:
function restore() {
if (!empty($this->head)) {
- drupal_set_html_head($this->head);
+ drupal_add_html_head($this->head);
Before change it made sense, because inside drupal_set_html_head we did $stored_head .= $data ."\n";
After the change this line is useless, because drupal_add_html_head withour $key param will not add anything
Remaining tasks
First issue should be fixed by MR ( it is as much close as possible to initial behaviour, in my view)
As a solution for second problem we just might just remove the
if (!empty($this->head)) {
drupal_add_html_head($this->head);
}from restore function
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | php_8.0_compatibility_fix-3292020.patch | 512 bytes | patelh84 |
Issue fork panels-3292020
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
driverok commentedComment #4
driverok commentedComment #5
renat33 commentedHello,
I've checked the issue using STR from description on PHP - 8.0.16, Drupal - 7.89.
The issue is fixed. There are no 'Array to string conversion in panels_cache_object->cache()' warnings on the page.
Best Regards
Comment #6
cafuego commentedThe warning is definitely present with PHP 8.1.
Comment #7
patelh84 commentedI am adding a patch which I have tested on my local and is working for me. After applying it the warnings are not displayed on the pages.
Comment #8
Holka_a commentedPatch Patch worked for me, thanks.
Comment #9
BrijeshParmar commentedThe patch #7 work fine for me.
Comment #11
joelpittetI had to prove to myself the
array_diff_keywas what we are doing here... as it appears we should be doing the same as what the CSS/JS is doing.https://3v4l.org/Y3aoM
Thanks for that elegant solution @driverok
Changed the init value but it's always an array and removed the
is_arraycheck because it's always true... now, I addressed the second part of this issue which was the restore function.I hope by finally making this "work" the way it was intended, it doesn't break something...
Comment #13
joelpittetComment #14
joelpittetAdding to the release plan #3157069: Plan for Panels 7.x-3.11