Hi
I have an error message when I try to create a node

Notice : Undefined property: stdClass::$nid in node_class_attributes() (ligne 24) in sites/all/modules/node_class/node_class.module

Comments

kropka’s picture

subscribe

drnikki’s picture

StatusFileSize
new1.33 KB

This is an issue with the nid not existing in form_state on submit.

Patch attached.

drnikki’s picture

Status: Active » Needs review
faisaljaved’s picture

I had same issue. Use hook_node_insert and hook_node_presave. Here is the code which works for me
/*
* insert new record for a node in node_class table
*/
function node_class_node_insert($node){
db_insert('node_class')->fields(array('nid' => $node->nid, 'css_class' => $node->node_class['css_class']))->execute();

}
/*
* Update node class
*/
function node_class_node_presave($node){
db_update('node_class')
->fields(array(
'css_class' => $node->node_class['css_class']
))
->condition('nid',$node->nid)
->execute();
}

Note: Please remove form_submit function (line 67 to 88).

drnikki’s picture

I didn't want to completely rewrite the author's module, but you'll see the attached patch uses hook_node_insert. Once s/he commits these patches, I'd be happy to remove _submit.

kingfisher64’s picture

I'm still getting the error in #1 after the patch on #2 is applied. The patch was successful but the error remains.

Edit: Once editing pre-existing content there is no error message, but upon creating new content it's output.

kingfisher64’s picture

can #4 not be implemented asap? It does say minimally maintained on the status. I'm sure some help to fix this would be appreciated rather than it being viewed as a takeover process.

This little mod will be very handy indeed once errors are fixed. :)

drnikki’s picture

StatusFileSize
new2.58 KB

Not sure how I missed this earlier, but sure enough - a clean checkout & patch from #2 and the error still appears. I'm attaching a patch with changes from #2 and the fix for the error.

kingfisher64’s picture

Great the error has gone, thanks drnikki.

drnikki’s picture

Status: Needs review » Closed (fixed)
Bernsch’s picture

Version: 7.x-1.0 » 7.x-1.1
Status: Closed (fixed) » Active

Hy!
The error is back in version 7.x-1.1: After install this module and i add a new content, i become this error message:

Notice: Undefined property: stdClass::$nid in node_class_attributes() (Zeile 31 von /var/www/mywebsite.com/sites/all/modules/node_class/node_class.module).

I use Drupal 7.17 and the node class module 7.x-1.1

Anonymous’s picture

This is weird. If you pull the project with git, this was the last commit and was way before 7-x-1.1. So it is a little confusing as to where 7-x.1.1 came from.

Bernsch’s picture

Status: Active » Closed (works as designed)

I test the git version and 7-x.1.1 in a new local environment an both versions works as design...
I don't know what was the problem before...

Dret’s picture

Status: Closed (works as designed) » Active

I got the same problem!

Please find a solution... my Drupal version is 7.22

Anonymous’s picture

Dret - if you use the 7.x-1.x version from git, you will not have this problem. However, the git version doesn't have the changes to put the node class items in the vertical tabs like the 7.x-1.1.

Can someone with git access merge 7.x-1.1 back into git, and then possibly could we have a 7.x-1.2 release be based upon that merge?

shivani.shah’s picture

I find out a simple solution to this...

Goto: node_class.module :
// Add submit handler for node_class module
Remove: $form['#submit'][] = 'node_class_form_submit';
Add : $form['actions']['submit']['#submit'][] = 'node_class_form_submit';

Bernsch’s picture

Status: Active » Needs work

@shivani.shah or Maintainers
Can you writhe a patch pleace?
Then we can test it by the community (RTBC)

nomorerice’s picture

Patch for Node Class Module:
line 29:
function node_class_attributes($node) {
+ if(isset($node->nid))
+ {
$ret = db_query('SELECT css_class FROM {node_class} WHERE nid = :nid',
array(':nid' => $node->nid))->fetchField();
return $ret ? $ret : '';
+ }
+ else
+ {
+ return '';
+ }
}

creatile’s picture

Thanks nomorerice with your patch in #18, The error message has disappeared

Bernsch’s picture

Status: Needs work » Reviewed & tested by the community

The code in #18 works fine!

@Maintainers: Pleace create a patch an commited to dev. Thanks!

kingfisher64’s picture

Thanks for suggestion in #18. Can someone who knows how to commit this?

moonray’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new694 bytes

Find attached an actual patch.

sandip choudhury’s picture

I have also got error -
Notice: Undefined property: stdClass::$nid in node_class_attributes() (line 31 of D:\xampp\htdocs\ultracorporatepixel.com\sites\all\modules\node_class\node_class.module).

I delete the below lines from 29 to 33 in node_class.module file -

function node_class_attributes($node) {
  $ret = db_query('SELECT css_class FROM {node_class} WHERE nid = :nid', 
    array(':nid' => $node->nid))->fetchField();
  return $ret ? $ret : '';
}

And add the below lines in that place from line 29

function node_class_attributes($node) {
 if(isset($node->nid))
 {
$ret = db_query('SELECT css_class FROM {node_class} WHERE nid = :nid',
array(':nid' => $node->nid))->fetchField();
return $ret ? $ret : '';
 }
 else
 {
 return '';
 }
}

And this works. Thanks nomorerice.

Anonymous’s picture

#18 works for me. The patch in #22 did not work both via git and manually.

mhamed’s picture

hi
with the drupal 7.24 it still gives the same error
with the comment #23 done the error disappeared
thanks

Stanto’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

That looks fixed with 7.x-1.3

joachim’s picture

Status: Reviewed & tested by the community » Closed (duplicate)

Yup, confirming that this is fixed in 1.3:

function node_class_attributes($node) {
  // dev note:
  // Get css attribute information ONLY if node already existed.
  // if we're here the $form[#node] object will have already been
  // created but it won't have an nid because it hasn't been saved
  if (!isset($node->nid)) {
    return "";
  }

  return db_query('SELECT css_class FROM {node_class} WHERE nid = :nid', array(':nid' => $node->nid))->fetchField();
}

Fixed in commit:

commit 88ceb91fa9ce28198ebf6f932d2bdc9df5ac2678
Author: Nikki Stevens
Date: Thu May 3 10:29:44 2012 -0400

Issue #1558112 #4160056 by drnikki: node save & edit errors

In which case, this issue should be closed.