Call to undefined method ConfigureAction::getEntity()

Created on 1 November 2024, 14 days ago

Problem/Motivation

I'm getting the following error when trying to modify field values on a view containing product variation types:

Error: Call to undefined method Drupal\views_bulk_operations\Form\ConfigureAction::getEntity() in Drupal\commerce_bulk\Plugin\Field\FieldWidget\BulkSkuWidget->formElement() (line 149 of modules/contrib/commerce_bulk/src/Plugin/Field/FieldWidget/BulkSkuWidget.php).

Steps to reproduce

Create a view of product variation types, configure VBO to modify field values, then try modifying a field value

Proposed resolution

The error occurs because the code assumes that the form object will always have a getEntity() method, but in this case, it's being called from a Views Bulk Operations (VBO) context where the form object is ConfigureAction which doesn't have this method.

The issue is that the code directly calls getEntity() on the form object without checking if the method exists. When using Views Bulk Operations, the form object is different and doesn't have this method.

The fix adds a check using method_exists() to ensure the form object has the getEntity() method before trying to use it. This will prevent the error when the widget is used in contexts where the form object doesn't support entity operations.

Remaining tasks

Patch to follow.

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States Dave Kopecek

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

Comments & Activities

Production build 0.71.5 2024