I added Viewfield to my Page content type and it works! The only problem is that on the edit/create page of any content type Page the following warning message: "invalid argument supplied for foreach() in /httpdocs/sites/default/modules/viewfield/viewfield.module on line 279" is displayed.

I have searched for a possible cause and/or solution for this warning and have had zero success. I thought I was on to something when I found this previous issue: http://drupal.org/node/646766 but it was marked duplicate of http://drupal.org/node/831574 and closed. However, the warning message in "#831574: Warning in array filter" is not same warning message I am receiving or the same warning message in http://drupal.org/node/646766 which seemingly documents the exact issue I am having.

In other words, I still don't know why I am receiving this warning message.

I am using the latest recommended release 6.x-1.0, but I also tried the development release 6.x-1.x-dev and I still receive the same error message.

Any help would be greatly appreciated.

Thanks in advance!

Comments

tritof’s picture

Hi
I had the same problem today, it appears first when I was adding new books with root-nodes of secondary links (the 2 content types have the viewfield embedded with CCK, first added to page and then duplicated to bookpage). Not sure, but it may be related...
The warning message disapear when I click once to go somewhere else in the website.

Cheers

sun’s picture

Status: Active » Postponed (maintainer needs more info)

Can you provide the PHP warning message (including file and line info) when running on 1.x-dev, please?

lel’s picture

Thank you for the responses and I sincerely apologize for taking so long to respond.

The book module is not enable on my website.

The warning for 1.x dev is as follows:

"warning: Invalid argument supplied for foreach() in /var/www/vhosts/domain-name.com/httpdocs/sites/default/modules/viewfield/viewfield.module on line 277."

shane.hairston’s picture

subscribing

keithm’s picture

Status: Postponed (maintainer needs more info) » Fixed

In the development version 6.x-1.x, the viewfield.module code around line 277 has been rewritten at this point. Please try this version and reopen if the problem recurs.

goz’s picture

Version: 6.x-1.0 » 6.x-1.x-dev
Status: Fixed » Patch (to be ported)
StatusFileSize
new721 bytes

I have same issue if my view only have default display.
I make a patch to resolve this (i just make git pull so the patch has been done on the last 6.x-1.x commit).

keithm’s picture

@GoZ Thanks for your patch, but I cannot duplicate this problem with viewfield-6.x-1.x-dev and views-6.x-2.12. I don't understand how any view with a single default display can have isset($view->display) == FALSE. Please provide specific steps to reproduce the problem.

EDIT: Corrected $view->default to $view->display.

goz’s picture

Status: Patch (to be ported) » Postponed (maintainer needs more info)

Problem is not isset($view->default) == FALSE but isset($view->display) == FALSE
To reproduce this, make a view with only default display. Don't create displays.
During node creation, in your cck field, choose this view and submit your form. Message appear.
Error message only appear at submission.

The view correctly displays in the node, no error during node display.

keithm’s picture

@GoZ I still cannot reproduce your problem.

This is what I tried.

Created a view 'test_view'. If I don't customize anything, attempting to save the view produces the message 'Display "Defaults" uses fields but there are none defined for it or all are excluded.' so I added single field, Node Title. At this point the test_view can be saved and run; it produces a list of all node titles linked to a node. Then I added a new viewfield to the Story content type. When adding it, I examined the value of $view->display in _viewfield_potential_references() using a debugger. Every view, including test_view, had a valid display property, and I received no warning. Then I updated the values in a Story node that existed before the viewfield was created by selecting 'test_view | Defaults' and no argument. Still no warning. Viewing the node shows that the viewfield is running test_view correctly.

goz’s picture

@keithm : I found why this error display. In _viewfield_potential_references(), you make foreach on $field['allowed_views'] but if in your cck viewfield (in content type cck settings) you select a view that you delete later, this view always be stored in cck viewfield (until you submit cck viewfield content type again).
So you make foreach on allowed_views stored and make views_get_view of a view that doesn't exist anymore.

To reproduce :
Make test view.
In your content type cck settings, add this view to your cck viewfield.
Delete this view
Create content of your content type. Error message display.
Go to your content type cck settings, submit your cck viewfield settings (view deleted has disapeard from checkbox)
No more error message.

So you should test !empty($view) before foreach ($view->display

keithm’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new805 bytes

@GoZ Now this makes sense to me. Thanks for investigating. Patch attached.

sun’s picture

Status: Needs review » Reviewed & tested by the community

Looks ready for me. For D7, we should create a separate issue and discuss proper error handling (throwing an error message, watchdog log message, field value validation, implementing views hooks to react on deletion of views, etc)

Status: Fixed » Closed (fixed)

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