Problem/Motivation

When using PHP 8.1 the following warning is displayed:

Deprecated function: Automatic conversion of false to array is deprecated in Drupal\metatag\Plugin\Field\FieldWidget\MetatagFirehose->formElement() (line 156 of modules/contrib/metatag/src/Plugin/Field/FieldWidget/MetatagFirehose.php).
Drupal\metatag\Plugin\Field\FieldWidget\MetatagFirehose->formElement(Object, 0, Array, Array, Object) (Line: 353)
Drupal\Core\Field\WidgetBase->formSingleElement(Object, 0, Array, Array, Object) (Line: 220)
Drupal\Core\Field\WidgetBase->formMultipleElements(Object, Array, Object) (Line: 111)
Drupal\Core\Field\WidgetBase->form(Object, Array, Object) (Line: 181)

Steps to reproduce

Not 100% sure of the case, it seems like somehow the item value contains invalid serialized data, which when unserialize is used FALSE is returned. Then when we are adding to $values[] later on this PHP warning is called.

Proposed resolution

Make sure that $values remains an array even upon unserialize() failing.

Comments

3li created an issue. See original summary.

3li’s picture

Status: Active » Needs review
StatusFileSize
new753 bytes
damienmckenna’s picture

StatusFileSize
new688 bytes

Thanks for reporting this bug and providing a patch.

How about always making sure that $values is always an array?

Status: Needs review » Needs work

The last submitted patch, 3: metatag-n3280904-3.patch, failed testing. View results

damienmckenna’s picture

Status: Needs work » Needs review
StatusFileSize
new828 bytes

Better comments. Also, the last test run shouldn't have failed.

damienmckenna’s picture

  • DamienMcKenna committed 3debf40 on 8.x-1.x authored by 3li
    Issue #3280904 by DamienMcKenna, 3li: Automatic conversion of false to...
damienmckenna’s picture

Status: Needs review » Fixed

Committed. Thank you!

Status: Fixed » Closed (fixed)

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

klemendev’s picture

It does not seem this fix was included in https://www.drupal.org/project/metatag/releases/8.x-1.22, was it?

damienmckenna’s picture

The change is still visible in the 8.x-1.22 codebase. If you are experiencing this problem please open a new issue so additional instances of this bug can be tracked down.

klemendev’s picture

I have checked and the change indeed is in 1.22. I was just asking because this change was not in the changelog/release notes of the release.