Problem/Motivation

Symptoms

When configuring Rules to use data from a VBO view an error message appears:
Warning: Invalid argument supplied for foreach() in _views_bulk_operations_get_field() (line 264 of .../sites/all/modules/views_bulk_operations/views_bulk_operations.module

Steps to reproduce

  1. Create a view of fields containing only a Content pane display.
  2. Disable the Views content panes module.
  3. Create a second view with a VBO field.
  4. Create a Rules component with an action loading entities from the VBO view.
  5. See the error message.

Original report:

Hi guys, I have a simple view with a VBO field that I am trying to loop through in a rule. Any action or condition referring to the VBO view is throwing out this error:
Warning: Invalid argument supplied for foreach() in _views_bulk_operations_get_field() (line 264 of .../httpdocs/sites/all/modules/views_bulk_operations/views_bulk_operations.module).

Any help please?

Proposed resolution

Insert a check for a non-array value of $view->field

Remaining tasks

Review the patch.

User interface changes

Warning message naming the faulty view instead of an error message apparently connected to the VBO view.

API changes

None

Data model changes

None

CommentFileSizeAuthor
#4 invalid_argument-2663056-4.patch890 bytesblackra
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rmedard created an issue. See original summary.

blackra’s picture

Category: Support request » Bug report

I am seeing this problem too. The cause is that $view->field is NULL for some views.

The view that is causing this for me has the following interesting properties:

  • View type: Fields
  • Only field in master display: taxonomy term list
  • Output of field is rewritten

I suspect that $view->field must be an array for any view containing a VBO field in the master display, in which case wrapping the guts of the function in a check for is_array($view->field) should be an adequate fix. However, I don't know enough about views to know what should happen when there is a VBO field in an overridden display.

I have changed the category to Bug report because this is clearly a software problem.

blackra’s picture

It turns out that inn my case the cause of the empty $views->field was actually a missing handler. I had created a content pane display and then disabled Views content panes. Reenabling the module caused $views->field to become populated with an array once more.

I think a fix should generate a meaningful error message reporting the problematic view, especially since it will not usually be the VBO view at fault. The meaningful error message might not be able to be very specific, but at least it can report the name of the view that is at fault.

e.g. Configuration problem detected in view "faulty_view". Check for disabled modules and deleted fields.

blackra’s picture

Status: Active » Needs review
FileSize
890 bytes

Here is a patch to check for a non-array value of $view->field and issue a warning. This should allow Rules to correctly populate its list of available VBO fields.

blackra’s picture

Issue summary: View changes
blackra’s picture

Issue summary: View changes
joseph.olstad’s picture

Symptom: Warning: array_unique() expects parameter 1 to be array, null given in views_bulk_operations_modify_action() (line 69 of /www/d754/sites/all/modules/contrib/views_bulk_operations/actions/modify.action.inc).

For us, patch #4 prevents the above warning.

izmeez’s picture

Patch in #4 continues to apply without difficulty to the 7.x-3.x-dev 2019-05-16