Warning: Attempt to assign property of non-object in views_field_view_handler_field_view->render() ...

This is due the $values variable to be expected an object in the render call. But the area render only passes a TRUE or a FALSE, whether the result was empty or not. For the latter case, there is already a fallback beahviour in line 361, but that only deals with "empty($values)". As $values might be TRUE, there has to be some additional handling to fix that warning.

I'll post a patch in the next comment.

Comments

derhasi’s picture

And there is the patch.

derhasi’s picture

Status: Active » Needs review
derhasi’s picture

StatusFileSize
new1.27 KB
new965 bytes

A little simpler approach, that simply casts the values to an object.

$empty = TRUE might occur, when the views result is empty, @see views_plugin_display::render_area().

Status: Needs review » Needs work

The last submitted patch, views_field_view-empty-area-1945678-3.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
+++ b/sites/all/modules/contrib/views_field_view/views_field_view_handler_field_view.incundefined
@@ -358,8 +358,8 @@ class views_field_view_handler_field_view extends views_handler_field {
+    if ($this->handler_type !== 'field' && !is_object($values)) {
+      $values = (empty($this->view->result)) ? (object) $values : reset($this->view->result);

$values is either the current row (in case this is used as field) or a boolean saying: do we want to render the area, if it's empty. This logic doesn't seem to be implemented here. So what about checking for (empty($view->result) && $empty === FALSE) { return ''; } The casting casting logic here is not required anymore and we could just provide an empty stdClass, as casting an boolean is odd, sorry.

derhasi’s picture

StatusFileSize
new1.62 KB
new1.76 KB

Oh, yes you might be right.

There's another solution that will handle the warning in a better way. In the case of an area handler, we do not need to touch the $values anyway. And in the case of empty === TRUE (for footer and header) nothing should be rendered at all?

Status: Needs review » Needs work

The last submitted patch, views_field_view-empty-area-1945678-6.patch, failed testing.

dawehner’s picture

+++ b/sites/all/modules/contrib/views_field_view/views_field_view_handler_field_view.incundefined
@@ -356,10 +356,15 @@ class views_field_view_handler_field_view extends views_handler_field {
+    if ($this->handler_type !== 'field' && $values === TRUE) {
+      return '';
     }

First: You are able to render a header/footer if there is an emtpy views result set, but even more important this method is called on empty areas, whch in this cause wouldn't be rendered at all. Glad to know that this is caught by the test coverage.

derhasi’s picture

Status: Needs work » Needs review
StatusFileSize
new940 bytes
new1.4 KB

Ah, ok, then I misunderstood your previous comment.

So in that case, the following patch should be enough. Let's try it again ;)

Status: Needs review » Needs work

The last submitted patch, views_field_view-empty-area-1945678-9.patch, failed testing.

derhasi’s picture

Status: Needs work » Needs review
StatusFileSize
new1.23 KB

Ah, sorry it will not work, due to the non-relative path. There is another patch.

btw: The above test failed due to a non-applicable test. As I saw in the code, the empty region is always called with $empty = FALSE, @see views_plugin_display::render_empty().

damiankloip’s picture

The fix looks ok, maybe it would be good to add a couple of tests for this?

damiankloip’s picture

Status: Needs review » Fixed

Committed to 7.x. Let's just get this in for now. I tested it and doesn't break anything :)

Also I amended the comments for the patch.

Status: Fixed » Closed (fixed)

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