1

I'm getting a strange error on a Views page, even though the page works. I get ten instances of this error:

Notice: Undefined index: field_video in include() (line 28 of 
/path/to/drupal/sites/all/themes/mytheme/templates/
views-view-fields--screenings--panel-pane.tpl.php).

Notice: Trying to get property of non-object in include() (line 28 of 
/path/to/drupal/sites/all/themes/mytheme/templates/
views-view-fields--screenings--panel-pane.tpl.php).

Here's the content of line 28:

if (preg_match('/media/', $fields['field_video']->content)) {
    unset($fields['field_featured_image']);
}

The idea is that if a node of the relevant content type has both a Video and a Featured Image, the view will drop the image and replace it with the video.

What's crazy is that the page renders just fine; the image disappears when the node has content in both fields. What's even crazier is that the error appeared after a minor tweak to the above code, so I reverted my change and it still throws this error, no matter how many times I flush my caches.

What is happening here? This very same code worked fine for a long time, but now I can't seem to get rid of this error!

  • do you have any content without a field_video? if even one content didn't, it could cause this error. usually this is mitigated by adding a if(isset($fields['field_video'}) in the if statement – Geoff Jun 14 '15 at 3:45
1

First thing to note is you're seeing notices, not errors. Notices are a less severe type of PHP error. It's an alert that notes script execution is continuing, but something is wrong that could be a bigger problem. In your case, the array element $fields['field_video'] doesn't exist,
thus trying reference a property $fields['field_video']->content on a non-existant object causes PHP to fire off notices.

As Geoff mentioned, this can occur if your view rows are loading nodes that don't produce this field and throwing an isset($fields['field_video']) && in your if statement should fix your template from making bad references.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.