I get a Notice (see Title) when adding new nodes to my Site.
Also get this when changing Settings in Modules. etc.

It makes no difference if it is an article or basic page - when pressing Save the
Notice occurs:
Notice: Trying to get property of non-object in node_page_title() (Line 2108 of /var/www/modules/node/node.module).

I opened the /var/www/modules/node/node.module by nano (ubuntu 12.04)
and looked for line 2108 that looks like

/**
 * Title callback for a node type.
 */
function node_type_page_title($type) {
  return $type->name;
}

/**
 * Title callback.
 */
function node_page_title($node) {
  return $node->title;
}

/**
 * Finds the last time a node was changed.
 *
 * @param $nid
 *   The ID of a node.
 *
 * @return
 *   A unix timestamp indicating the last time the node was changed.
 */
function node_last_changed($nid) {
  return db_query('SELECT changed FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetch()->changed;
} 

I don't know why I get this message? I have no Menu Blocks active (I googled for this Notice...)

I also get this message when changing or deleting a node.

The Details in my Logs say

Type PHP

My System
ubuntu server 12.04
apache 2.2.22
php 5.3.10

mysql 5.5.24

I say many thanks to everybody who can help me with that.

Comments

chrisssi’s picture

Issue summary: View changes

Notice was written in german :(

Leeteq’s picture

Assigned: chrisssi » Unassigned
Status: Active » Postponed (maintainer needs more info)

Please provide some more background information for this issue:
- did this happen immediately after installing or upgrading, not after enabling some contrib. modules?
- is this on a brand new 7.15 installation, or an upgrade from a previous drupal version? (if so, from which version?)
- when you try to install a brand new 7.15 on the same server, without enabling any extra contrib. modules, do you get the same problem?
- does your watchdog log show any other errors around the same time this occurred?

(please do not assign issues to yourself unless you are going to work on a fix for it yourself)

chrisssi’s picture

Ok, first I appologize for assigning the issue to myself - I'll remember next time.

So, I got this message since I use Version 7.9 or 7.10 don't know exactly.
In the past I commented out this line and no notice occured - but every time I upgrade to a new
Version - this line is back (sure) - so this time I posted the issue to get help - late I know!!

Never the less - I have disabled all installed modules -

My modules (outer Core):

Apache Solr Autcomplete
Apache Solr Search Integration
ACL
Advanced Forum
PHP Mailer
Views
DHTML Menue
Facet API
Libraries
Entity API
Rules
Print (Email, PDF)
Localization Update
Translation helper
IMCE
Privatemsg
Flag
Wysiwyg

I disabled all modules and uninstalled them Admin -> Modules -> Uninstall
I cleared Caches

The Notice still appears when adding content, editing content or although changing settings.

Other wise - when commenting out line 2108

function node_page_title($node) {
  return $node->title;

the Notice isn't there but this was and is a stupid way to get rid of this one.

Hope these Infos help a bit.

Oh, and no other errors etc when getting this notice (Watchdog only reports the new added content or edited content beside this Notice - so normal behaviour.)

Regards chrisssi

Leeteq’s picture

Version: 7.15 » 7.x-dev
Status: Postponed (maintainer needs more info) » Active

ok, thanks for the background information.
(no need to apologize, I am just informing you, tons of people does this, so it is not intuitive what that assignment is for :-) )

This means that this issue is not specific to 7.15, so therefore I move it onto the 7.x-dev branch for further discussion.

This is not necessarily a core bug either, though.
Check out this issue which might have some relevance for the troubleshooting:
#1187776: Use with Menu Block causes PHP notice and active trail problems
(if it helps, please report back here)

chrisssi’s picture

Thanks Leeteq,

I modified the node.module file in line 2108 that way:

from

function node_page_title($node) {
  return $node->title;

to

function node_page_title($node) {
  if (is_numeric($node)) {
    $node = node_load($node);
  }
  return $node->title;
}

refering to #1187776
I tested some new entries - no Notice appears :-)
Then I edited some of the existing ones - also no php Notice after submit.
I 'll testing that a little longer ...

I don't use the menu_block module.

rob49152’s picture

This is the code I use to fix the issue. It simply checks to see that the 'title' value exists before trying to send it back. Fixes the problem for me until I update the core version I am running

node.module - starts line 2104

/**
 * Title callback.
 */

function node_page_title($node) {
  return $node->title;
}

with

/**
 * Title callback.
 */
function node_page_title($node) {
  if (property_exists($node, 'title')) return $node->title;
}
dman’s picture

The fix I found (not a core hack, though I do agree with core dealing with this better, as illustrated above) was to remove some database corruption from my menu_links table.

http://drupal.org/node/429910#comment-6641288

This may work for someone. Issue found in 7.12 FWIW. I needed to remove existing problems before feeling comfortable to upgrade.

japanitrat’s picture

#6 did not fix it for me. Will do the hack from #4 for now :(

rooby’s picture

Status: Active » Closed (duplicate)
rooby’s picture

Issue summary: View changes

Also Notice when changing Settings, Modules

asiby’s picture

Issue summary: View changes

Guys,

You can achieve the same goal without hacking the core.

/**
 * Implements hook_menu_alter
 */
function [YOUR MODULE]_menu_alter(&$items) {
  $items['node/%node']['title callback'] = '[YOUR MODULE]_page_title';
}

/**
 * Helper function to replace node_page_title
 */
function [YOUR MODULE]_page_title($node) {
  if (!$node) {
    return '';
  }

  if (is_numeric($node)) {
    $node = node_load($node);
  }
  return !empty($node->title) ? $node->title : '';
}
leisurman’s picture

Has anyone tried #9

berliner’s picture

@leisurman I haven't tried it personally but #9 looks like a good temporary solution.

leisurman’s picture

Thanks berliner,
Does the #9 code go into template.php or create a custom module with it.

leisurman’s picture

I tried it in a module but got an error. I did change the [YOUR MODULE].

system non_object module enabled.
3298 13/Mar 09:45 error php EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7880 of /var/www/html/upgrade2a/includes/common.inc).

bsufan17’s picture

#9 worked for me. My issue was being caused by a custom module I created, so I just added the code from #9, to my module. Worked like a charm!

texas-bronius’s picture

Yep-yep, #1709914-9: Notice: Trying to get property of non-object in node_page_title() (Zeile 2108 von /var/www/modules/node/node.module). (#9 above) workaround above makes sense and does work.

According to #1697570: _menu_load_objects() is not always called when building menu trees, the issue occurs when we try to build a menu twice (like for unequal displays in two different blocks). The specific issue is that menu translation receives just an integer nid rather than the expected $node object on second+ passes.

If core is ever patched to address this issue, then #9s custom module code won't be necessary anymore.