Problem/Motivation
Right after I upgraded PHP to version 8.1.4 following error appears :
Deprecated function: unserialize(): Passing null to parameter #1 ($data) of type string is deprecated in Drupal\viewsreference\Plugin\Field\FieldFormatter\ViewsReferenceFieldFormatter->viewElements() (line 75 of modules/viewsreference/src/Plugin/Field/FieldFormatter/ViewsReferenceFieldFormatter.php).
attached Patch, please try to test if it works for you.
| Comment | File | Size | Author |
|---|---|---|---|
| #29 | viewsreference-3273497-27.patch | 954 bytes | drupalninja99 |
| #26 | viewsreference-3273497-26.patch | 1.5 KB | bogdan.dinu |
| #21 | 3273497-23.patch | 5.33 KB | ikeigenwijs |
Issue fork viewsreference-3273497
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
avpadernoComment #3
anneke_vde commentedThe solution worked, but the patch couldn't by applied with composer patches.
So here's is the newly created patch
Comment #4
paul.kim commentedThis error also occurs in src/Plugin/Field/FieldType/ViewsReferenceItem.php, I've added a similar patch here for that issue.
Comment #5
coaston commentedHi Paul,
Thank you for your patch, it looks fine ,however you should merge both patchs #3 and #4 into one file because people will use the latest path #4 but it won't fix the issue which was resolved in #3.
Comment #6
avpadernoComment #7
greggmarshallHere's the combined patch
Comment #10
rodrigoaguileraIn my case $values['data'] is not even set in the array so I think using isset is more appropriate to ensure unserialize is not even called whne there is no data.
Opened a merge request.
Comment #11
anybody@rodrigoaguilera thanks, that's the only real solution here, all patches are wrong. I'd vote for an !empty() instead of isset() to be even safer!
Confirming this issue!
Comment #12
anybodyComment #13
anybodyI made that change.
The issue btw also leads to a warning:
Comment #14
greggmarshallI just noticed the warning in #13 as well.
Comment #15
interdruper commentedI also noticed that https://git.drupalcode.org/project/viewsreference/-/merge_requests/23.patch breaks the views filtering when argument is set to feed a contextual filter.
Comment #16
jrochate commentedSame here as #15. Path breaks filtering when using viewsreference with argument using paragraphs.
Comment #18
neclimdulYeah, there was a little bug in the merge request. The new commit should fix it.
Comment #19
g.rocchini commentedHello, any news about this issue?
Will be available a release soon or we should use the patch?
Thanks!
Comment #20
grevil commentedMR by @neclimdul LGTM!
(It also fixes the issue mentioned in #13).
Comment #21
ikeigenwijs commentedcurrent patch, for composer
Comment #24
seanbCommitted, thanks everyone! Had to reroll, so please help test the latest dev version!
Comment #26
bogdan.dinu commentedThe warning still exists on Drupal 10 with php 8.1 and viewsreference 2.0-beta6.
I attached a patch that fixes the issue in \Plugin\Field\FieldType\ViewsReferenceItem and Plugin\Field\FieldFormatter\ViewsReferenceFieldFormatter as they are using the 'data' array key without checking if it is set.
PS: the warning is generated only for the FieldType but I think adding the check for the FieldFormatter doesn't hurt :)
Comment #27
ilfelice commentedHowdy,
Patch from #26 applied cleanly on a Drupal 10.1 install with newly installed viewsreference 2.0-beta6.
After applying the patch, the error is gone.
Comment #28
drupalninja99 commentedWhen I tried to apply #26 to the latest 2x dev, composer just hangs or says it can't apply the patch.
Comment #29
drupalninja99 commentedI am attaching a small patch that resolves the error I am getting in ViewsReferenceFieldFormatter.php.
Comment #30
dewancodes commentedI tried #27 on drupal 10 and it worked fine for me as error gone. Thanks @drupalninja99.
Comment #31
xeiro commented#3 applies and removes the error on 9.5x / php 8.1.
Comment #32
norman.lol#29 makes the views arguments not being respected anymore. Exactly what's described in #3405177: Contextual filters not respected when used in paragraph.
Everybody just needs to update to 2.0-beta7.
Comment #33
anybody@seanB: Reading the comments here, should this be reopened or should someone please create a follow-up issue (I'd suggest so!)
Comment #34
steveoriolI have the error on viewsreference:2.0.0-beta7 end php 8.2
Deprecated function: unserialize(): Passing null to parameter #1 ($data) of type string is deprecated in Drupal\viewsreference\Plugin\Field\FieldFormatter\ViewsReferenceFieldFormatter->viewElements() (line 98 of modules/contrib/viewsreference/src/Plugin/Field/FieldFormatter/ViewsReferenceFieldFormatter.php).Comment #35
daletrexelI've opened a new issue #3423648: unserialize() of NULL deprecation returns to ViewsReferenceFieldFormatter since there has been a re-emergence of a problem that this issue had resolved when it was closed.
#3380691: Issue 2919092 breaks BC and causes issues for existing sites, which was included in the beta7 release, allows null data to be passed to the unserialize() function again, without checking whether data might be null or not:
unserialize($item->getValue()['data'], ['allowed_classes' => FALSE])As I and others have found, null 'data' is possible in views reference fields (likely those saved a while ago when expectations for this field were looser), so we really need to bring back a sanity check here before calling unseralize().My new ticket proposes a solution to re-fix this particular instance (line 98 of ViewsReferenceFieldFormatter.php)
(The 'data' field stores the "extra settings" configuration, which is also involved in #3402036: Configuration schema for "Enable extra settings" (title,pagination,...) incorrect. I wouldn't be surprised if this is related, but so far I've been unable to reconstruct what previous scenario allowed an empty 'data' field to begin with. It was likely in Drupal 9, which I no longer have an easy way to test.)
Comment #36
javier_rey commentedWithout patch number 27, I get the warning mentioned in the issue.
But when applying it I don't get any "value" in the method "public function alterView(ViewExecutable $view, $value)" of my "
ViewsReferenceSetting custom setting.
My version is 2.0-beta7.
Comment #37
batkor#36 confirm