Greetings

I have the following notice when trying to use the webform as a block with display mode set to "Form only".
Notice: Undefined property: stdClass::$content in webform_block_view() (line 1759 of webform.module).
Which in turn, doesn't render the form. Clearing cache, fixes it for a while, but after some time or form submissions back to "Notice" without the form.

In general, after the 7.21 Core update I had a lot of problems with undefined property and unfortunately, one of them was with the webform block.
I've checked line 1759 and the problem is on "$content = $node->content['webform']"

// Generate the content of the block based on display settings.
  if ($settings['display'] == 'form') {
    webform_node_view($node, 'full');
    $content = $node->content['webform'];
  }

I am not sure why it has such a problem, but after a search I start to think that the culprit is my custom .tpl files.
Haven't check it yet.

Any help will be appreciated.
Thank you.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cyper983’s picture

Hi, try to rewrite the code above with this, it worked for me!!

// Generate the content of the block based on display settings.
if ($settings['display'] == 'form') {
    webform_node_view($node, 'full');
    if(isset($node->content['webform'])){
        $content = $node->content['webform'];
    }
}
谢艳’s picture

Issue tags: +Yes, +it's right!

because there is no any forms in your new webform, so stdClass::$content is null!!

crutch’s picture

Just encountered same. Was working before but now when viewing page with block form, getting the same error. Also, block has disappeared from block list so can't find it to do anything with it. Flush cache has no effect.

+ Webform is not available in content list and it states "There are currently no webforms on your site." @admin/content/webform

solution #1 didn't fix

apologies, we had a feed overwriting NIDs

Collins405’s picture

I am now having this problem as well, the site was working fine until I added a new basic page, and the error started showing.

I am using webform 4, and managed to stop the error showing from post 1.

In webform 4, the error appears for line 2032 of webform.module.

I changed it to the following, and the errors stopped. What's weird is that there wasn't a webform in a block, or even a webform on the only page the error was showing on.

  // Generate the content of the block based on display settings.
  if ($settings['display'] == 'form') {
    webform_node_view($node, 'full');
    if(isset($node->content['webform'])){
        $content = $node->content['webform'];
    }
  }
  else {
    $content = node_view($node, $settings['display']);
  }
bittu.rohan’s picture

Well, I just logged in to say THANK YOU to you guys to posting a resolution to this issue.
I faced the same issue all of a sudden today when I am really almost done with my project. You saved my project...

Thanks again guys !

Yes, the above code worked for me...

itbazar’s picture

Issue summary: View changes

Thank you!

quicksketch’s picture

Priority: Major » Minor
Issue tags: -Yes, -it's right!
FileSize
540 bytes

I guys, I'm not sure how this error is possible to reproduce. It seems like you'd have this problem only if your site had been misconfigured, or you previously had a Webform node in a block but then later deleted the form. Anyway, suppressing the notice is easy enough, so I've wrapped it in an isset() check as suggested by @chriscollins405.

quicksketch’s picture

Status: Active » Fixed
FileSize
767 bytes

Actually, I found that the approach in #7 would just result in a different PHP notice if Contextual module was disabled, so I used this approach to set the $content variable to an empty array instead of NULL to prevent errors.

Status: Fixed » Closed (fixed)

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

fenstrat’s picture

Version: 7.x-3.18 » 8.x-4.x-dev
Assigned: Unassigned » fenstrat
Status: Closed (fixed) » Patch (to be ported)

Needs porting to 8.x-4.x.

fenstrat’s picture

Version: 8.x-4.x-dev » 7.x-3.18
Assigned: fenstrat » Unassigned
Status: Patch (to be ported) » Fixed

Committed 4025004 to 8.x-4.x.

  • Commit 61bf490 on 8.x-4.x by fenstrat:
    Issue #1968434 by quicksketch | Raytracer: Undefined property: stdClass...

Status: Fixed » Closed (fixed)

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