PHP notice: Undefined property: stdClass::$format

Pasqualle - October 12, 2008 - 23:58
Project:Drupal
Version:6.x-dev
Component:node.module
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Issue tags:Quick fix
Description

notice: Undefined property: stdClass::$format in drupal-6.x-dev\modules\node\node.module on line 1037.

when node does not have a body field then the node preview shows a PHP notice

repro:
1. clean install
2. admin/content/node-type/page clear the "Body field label" and save
3. node/add/page fill Title with anything and click preview

#1

webmasterkai - December 5, 2008 - 02:25

Any word on this?

#2

qutoz - December 17, 2008 - 22:49

Hi,
After making some researches and diving inside Drupal code, I got some ideas about what is happening there:

1- admin/content/node-type/page : clear the "Body field label" and save
2- node/add/page : "Input format" fieldset removed automatically, because it has nothing to do in case of "Body" field not there.
3- "Input format" fieldset contains 2 radio buttons (the name of radio group is "format").
4- When you click "Preview", actually the form is submitted, so the form values should be stored inside $form_state['values'] variable as array.
5- $form and $form_state variables are passed to node_form_build_preview function (in node.pages.inc), which passes them to node_form_submit_build_node function to build $node object, which passes them to node_submit function (defined in node.module), at this point exactly $node object is built and created with properties, according to those posted by the form, so it may or may not contain the "format" property.
6- After that, $node object is passed to series of functions, till it reaches "node_view" function (in node.module), where the error is happening due to line 1037:

<?php
  $node
->body = check_markup($node->body, $node->format, FALSE);
?>

where the $node->format does not exist.

Note: This is not happening in case of viewing the content type after submission, because $node object is loaded with "format" property by default.

Currently I have 3 suggestions

1- In case that there's no "Body field", Drupal should keep the "Input format" fieldset with its radio buttons.
2- Building $node object in a way that it always contains "format" property.
3- Preventing the submission of content type without "Body field" :)

If anyone of these suggestions, or even any other suggestions, is OK, I want to make the patch myself, if it is OK with you guys :)

#3

Pasqualle - December 13, 2008 - 22:56

1. no - I don't need a format when I do not need the body
2. yes
3. no - I need a content type without body

#4

qutoz - December 17, 2008 - 22:54

Hi,
Sorry for being late I just want to be sure that there are no new suggestions or comments.
Please take care that I added a new part in bold to my first comment.
So here is the patch and thanks for your patience.

AttachmentSize
preivew_contents_without_body.patch 483 bytes
Testbed results
preivew_contents_without_body.patchre-testing

#5

swentel - December 17, 2008 - 23:21
Version:6.x-dev» 7.x-dev
Status:active» needs review

Can confirm this, this is also present in D7, so changing version. Patch in #4 fixes D6 branch, attached in #5 is for drupal head.

AttachmentSize
preview_contents_without_body-D7.patch 728 bytes
Testbed results
preview_contents_without_body-D7.patchre-testing

#6

qutoz - December 17, 2008 - 23:30

Thanks swentel for your attention. :)

#7

swentel - December 25, 2008 - 15:32

Chasing HEAD

AttachmentSize
preview_contents_without_body-D7.patch 677 bytes
Testbed results
preview_contents_without_body-D7.patchre-testing

#8

swentel - January 10, 2009 - 10:15

Tagging & bumping.

#9

Damien Tournoud - January 10, 2009 - 11:00
Status:needs review» needs work

A new argument for my "put body and format in a same element".

Format is an integer, this should be $node->format = 0;.

#10

swentel - January 10, 2009 - 11:03
Status:needs work» needs review
AttachmentSize
preview_contents_without_body-D7_0.patch 750 bytes
Testbed results
preview_contents_without_body-D7_0.patchre-testing

#11

catch - January 11, 2009 - 19:56
Status:needs review» reviewed & tested by the community

Looks good the input format changes will likely change how this works anyway (and with tests), so RTBC.

#12

webchick - January 17, 2009 - 20:56
Version:7.x-dev» 6.x-dev

Committed, thanks!

Moving down to 6.x.

#13

Gábor Hojtsy - February 16, 2009 - 14:39
Status:reviewed & tested by the community» fixed

Thanks, committed to Drupal 6 as well.

#14

System Message - March 2, 2009 - 14:40
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.