Warning: Trying to access array offset on value of type null in commerce_product_reference_views_data_alter() commerce_product_reference.views.inc

Created on 8 December 2024, 13 days ago

PHP 8+ on Commerce for D7 causes some errors on cache flush:

Warning: Trying to access array offset on value of type null in commerce_product_reference_views_data_alter() (line 86 of sites/all/modules/contrib/commerce/modules/product_reference/includes/views/commerce_product_reference.views.inc).

Warning: Trying to access array offset on value of type null in commerce_product_reference_views_data_alter() (line 93 of sites/all/modules/contrib/commerce/modules/product_reference/includes/views/commerce_product_reference.views.inc).

Warning: Trying to access array offset on value of type null in commerce_product_reference_views_data_alter() (line 94 of sites/all/modules/contrib/commerce/modules/product_reference/includes/views/commerce_product_reference.views.inc).

I have no idea what I'm doing, but the following fixed the errors:

Line 86 Fix

-      $replacements = array('@entity_type' => $entity_info['label'], '!field_name' => $field['field_name']);
+     $replacements = array('@entity_type' => isset($entity_info['label']), '!field_name' => $field['field_name']);

Line 93 Fix

-      'base' => $entity_info['base table'],
+     'base' => isset($entity_info['base table']),

Line 94 Fix

-     'base field' => $entity_info['entity keys']['id'],
+    'base field' => isset($entity_info['entity keys']['id']),

Posting since there are no other references online talking about this.

There's no guarantee this fix won't break something else.

If there's a more elegant fix, please feel free to provide.

πŸ› Bug report
Status

Active

Version

1.0

Component

Views integration

Created by

πŸ‡ΊπŸ‡ΈUnited States philsward

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024