Problem/Motivation

please see the link: https://php.watch/versions/8.1/internal-func-non-nullable-null-deprecation.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Sergiu Stici created an issue. See original summary.

sergiu stici’s picture

StatusFileSize
new5.96 KB

please review the patch.

damienmckenna’s picture

Status: Active » Needs review

Thanks for reporting the bug and providing a patch. Let's see what the testbot says.

eugene bocharov’s picture

Status: Needs review » Needs work

Thanks @Sergiu Stici for working on this.
As I can see, test errors are caused by page_manager module, which also requires edits to be PHP 8.1 compatible. So, this is outside metatag module.

I just recon, not all occurences of explode() parameters should be escaped but only those where we really can expect NULL value.

For exapmle

$token_types = empty($default_type) ? [] : [explode('__', $default_type)[0]];

$default_type can not be NULL as it's checked before

Or here

        foreach ($tokens as $name => $original) {
          $field_name = explode(':', $name)[0];

         // ...
        }

$name can not be null as this is an array key and according to PHP manual Null will be cast to the empty string, i.e. the key null will actually be stored under "".

So I think it would be better to look at each case of explode() individially.

damienmckenna’s picture

Let's get this into the next release, it's blocking progress in other issues.

eugene bocharov’s picture

Status: Needs work » Needs review
StatusFileSize
new1.39 KB

I've looked at all explodes in the module and acutally I see only one place where we can expect NULL as argument. This is where the tests fail \Drupal\metatag\Form\MetatagDefaultsForm::form line 161. Instead of just using ?? I suggest enclose a couple lines in if to not perform redundant operations if metatag id is not defined yet.

if ($metatag_defaults_id = $metatag_defaults->id()) {
  $type_parts = explode('__', $metatag_defaults_id);
  $entity_type = $type_parts[0];
  $entity_bundle = $type_parts[1] ?? NULL;
}

$groups = isset($entity_type) && !empty($entity_type_groups[$entity_type]) && !empty($entity_type_groups[$entity_type][$entity_bundle]) ? $entity_type_groups[$entity_type][$entity_bundle] : [];

The patch is attached.

I still expect one test failure because of page_manager_ui module.

Status: Needs review » Needs work

The last submitted patch, 6: metatag-php81-explode-null-6.patch, failed testing. View results

eugene bocharov’s picture

As expected. The source of remaining error is on the page_manager_ui module side.

damienmckenna’s picture

StatusFileSize
new1.05 KB
new1.55 KB

Thanks! Let's simplify the logic a little.

damienmckenna’s picture

Status: Needs work » Needs review
damienmckenna’s picture

I opened #3263077: PHP 8.1 compatibility fixes for Page Manager for the Page Manager problem.

Status: Needs review » Needs work

The last submitted patch, 9: metatag-n3261505-9.patch, failed testing. View results

damienmckenna’s picture

Assigned: sergiu stici » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.87 KB

Let's move the Page Manager tests out of the way, for now.

Status: Needs review » Needs work

The last submitted patch, 13: metatag-n3261505-10.patch, failed testing. View results

eugene bocharov’s picture

I don't know what does it mean, but I had no errors testing locally, so ran retest and now the testbot shows no errors as well.

damienmckenna’s picture

Status: Needs work » Fixed

I've committed #13 and opened #3263140: Reenable Metatag Page Manager tests when it works with PHP 8.1 for dealing with Page Manager. Thank you all for collaborating on this!

damienmckenna’s picture

Issue tags: +PHP 8.1

Status: Fixed » Closed (fixed)

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