Problem/Motivation
If you change the attribute field on a product variation to use an Entity Reference View to filter to options there is a fatal error in commerce_product_field_views_data_alter() because $handler_settings['target_bundles'] is not set.
Proposed resolution
Check that the reference field is using the default handler before altering
if ($field->getSetting('handler') == 'default:commerce_product_attribute_value')
Original report by @orangeicebear
i got this Warning
Warning: array_values() expects parameter 1 to be array, null given in commerce_product_field_views_data_alter() (line 33 of modules/contrib/commerce/modules/product/commerce_product.views.inc).
Warning: reset() expects parameter 1 to be array, null given in commerce_product_field_views_data_alter() (line 34 of modules/contrib/commerce/modules/product/commerce_product.views.inc).
Comment | File | Size | Author |
---|---|---|---|
#10 | 3133003-10.patch | 689 bytes | jsacksick |
| |||
#3 | fix-warning-3133003-3.patch | 666 bytes | cobenash |
Comments
Comment #2
cobenashConfirmed error.
Comment #3
cobenashI think the problem was caused because I deleted the default product type.
But I think this is a proper move that the user may do, so I create a patch to fix the warning.
Comment #4
narendra.rajwar27Comment #5
narendra.rajwar27Fix for the failed test cases.
Comment #6
narendra.rajwar27Comment #7
narendra.rajwar27Patch issue in #6, adding updated patch after correction.
Comment #8
narendra.rajwar27Comment #9
dwkitchen CreditAttribution: dwkitchen at Centarro commentedUpdated the cause of the issue and provided patch
Comment #10
jsacksick CreditAttribution: jsacksick at Centarro commentedI think checking if the "target_bundles" setting isn't empty is a better option.
That still leaves the opportunity to define another entity reference selection handler, that isn't the default one and that still uses the same setting.
@dwkitchen: let me know if this approach still works for your usecase.
Comment #11
dwkitchen CreditAttribution: dwkitchen at Centarro commentedYep good idea, resolves issue
Comment #14
jsacksick CreditAttribution: jsacksick at Centarro commentedCommitted! @dwkitchen: Thanks for confirming that the fix works as expected!