Every successful search result completed by Search by Page is giving me 12 identical PHP notices:
"Notice: Trying to get property of non-object in node_page_title() (line 2073 of basepath/modules/node/node.module)."

This problem does not appear when using the core search and only happens when a search result is found using Search by Page Nodes Module. The search appears to function correctly despite the notices.

I am using the latest 7.x-1.x-dev as of today and Drupal 7.2

Thanks,
Jason

CommentFileSizeAuthor
#29 1187776.patch371 bytesstixes
#4 117666-php-notice.patch594 bytesjhodgdon

Comments

jhodgdon’s picture

That's interesting. I'll investigate. Thanks for reporting this!

aaronc’s picture

Have the same issue with 7.x-1.1 and Drupal 7.0.

aaronc’s picture

Things fail after search_by_page_page_content invokes block_page_build on line 493. I can email you a stacktrace if you like. But due to time constraints of my own, I patched my install to not bother rendering blocks.

jhodgdon’s picture

StatusFileSize
new594 bytes

I am unable to reproduce this error, although I have PHP set to display even "Notice" messages. I tested using Drupal 7.2 and Search by Page 7.x-1.x-dev. It is not giving me any PHP notices on the search results page (I am seeing notices from another contrib module I have enabled, so I know that notices are in general visible).

I see that two people are reporting this same problem, so I know it exists, but unless I can make it happen, it's difficult for me to fix it.

Hmmm... So I'mjust trying to think through what might be happening... The error is coming when node_page_title() calls
$node->title
so apparently it's getting $node not being an object. That $node object is likely coming from menu_get_item()... I'm wondering if this patch would fix this problem -- can either of you try it out?

Other than that, I'm not sure what else to try, since I cannot see the problem. Maybe you both have a particular block enabled in your theme that is triggering the error? Search by Page renders the page to make a search excerpt on the Results page, so anything happening during page rendering could trigger something like this. It's hard to track down.

jhodgdon’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 117666-php-notice.patch, failed testing.

jhodgdon’s picture

Status: Needs work » Needs review

I've committed the change above to the DEV release of 7.x-1.x-dev (should be available for download within 24 hours if you want to try it out). It shouldn't break anything.

jasondecamp’s picture

I installed the most recent dev version and there was no change in the notices. Your comments about it being a block led me to try disabling all of the blocks one by one on my search results page and sure enough, it appears that there is some sort of interference with the Menu Block module. When a page renders both a menu block and a search by page nodes result on my site, that is when the notices pop up. An interesting side effect that I had not noticed before: any primary level menu item that has a search result or has a child page search result is converted to uppercase. Not sure if that info can help or not, but it can't hurt.

jhodgdon’s picture

Status: Needs review » Needs work

Upper case?!? that sounds a bit odd, to say the least.

OK, anyway, knowing that Menu Block is the problem helps. I can at least investigate that, and see if it can be fixed.

jasondecamp’s picture

OK, the uppercase is not a direct consequence of the interference between these two modules, but it is an indirect one. The menu-block is assigning "active-trail" to everything that appears in the search results. I have a style set that transforms the main level active trail item uppercase. Not sure how that didn't occur to me sooner, but there you go.

I am also noticing that each menu item has many "active-trail" classes applied to them. Not sure if this is one for each appearance of the keyword, or one for each menu descendant that has one.

If you are interested in seeing how this is working on my development site you can see it here:
http://cleanpath.fourfightingfoxes.com/

jhodgdon’s picture

This doesn't sound good. It's a consequence of the way Search by Page compiles the search results page -- it renders each result as a page, and then gets an excerpt from the rendered page (to highlight the keywords). I thought I had gotten around most of the side effects of this by resetting some static variables, but obviously it's not completely working.

So I'll have to get Menu Block, take a look at what it is doing, and see if I can fool it into ignoring all but the real page (the search results page).

jasondecamp’s picture

The "active-trail" additions in menu-block appear to be a separate issue from the one that I created this thread for, so it should possibly be moved to a new thread, or maybe this thread should be renamed. As you can see by searching for "solar", and "energy" separately on my development site, these two issues do not always occur simultaneously.

Thanks for your help and responsiveness jhodgdon!

jhodgdon’s picture

OK... I installed the Menu Block module, and added a menu block to the page.

However, when I do a search, I am still not seeing
(a) the error message originally reported (I have my PHP error level set to the highest level of warnings)
(b) the menu block items getting set to active when the page they refer to is in the search results.

For instance, node/1 is in the menu block, and when I go to node/1, it is definitely marked "active" in the menu block, but when I search for a word that is on that page, its entry is not marked active in the menu block.

So, I'm still not sure what to do to debug this. Any ideas on how I can get this to show up on my test setup?

One thing I remembered is that there was a suggested fix on a somewhat related issue here:
http://drupal.org/node/1040002#comment-4462812
I haven't put that fix into Search by Page 6.x or 7.x yet, but it looks like it might help with the active trail part of your problem anyway? That person was using Menu Trails (which doesn't exist in 7.x).

webankit’s picture

+1 I got this error thrice when I send an email using Print

jhodgdon’s picture

Getting this error when sending an email isn't likely to be related to Search by Page... is it?

webankit’s picture

I may be mistaken but this error can have other core origin rather than in Print Module
Suggestions?

jasondecamp’s picture

So here is more details about my setup if it helps you to make sure we are comparing apples to apples:
The only Search by Page modules active are Search by Page, Search by Page Node, Search by Page Paths
Search by page settings:
One environment, set to default, only one node content type is being indexed, display excerpts with keywords highlighted, I only have one path set for indexing and that is a views page.
Search Settings:
Active search modules - Only search by page
Default search module - Search by page

Perhaps the order of rendering the Menu Block matters. For me, the menu block is located in the page footer and loads after the main content. If the menu block loads first, then maybe the active-trail classes are not applied?

Here is some more information I was able to figure out by trying different permutations of content: By unpublishing my content one node at a time I was able to determine that these notices only appear when the content I am finding in the search does not have a menu item associated with it.

Here is how you can try to reproduce this error:
1) Create a couple of nodes that are indexed by Search by Page Node
2) Make sure that you have a menu block that is loaded after the main content is loaded, and that has at least one link to an indexed node
3) Make sure that you have at least one search result that is a published node that has no menu item associated to it.
4) When you perform a search that returns the non-menu'd item you should see the notices
5) When you perform a search that returns the menu'd item you should see the additional "active-trail" classes added to the menu item. (they are added to the anchor tag, not the list item).

jasondecamp’s picture

I also just discovered that the menu block must be set with the following settings (and confirmed that the load order does not matter):
advanced options - Expand all children of this tree

jhodgdon’s picture

babbar.ankit: This issue is in the Search by Page project. If you are having a similar error that is unrelated to the Search by Page project, then you need to file an issue in another project (perhaps Print or Drupal Core?).

jhodgdon’s picture

RE #17/#18 - that is very helpful and detailed information - thanks! I will try later today (hopefully) and see if I can reproduce your issue(s).

jasondecamp’s picture

Regardless of the cause at this point, a solution that works for my needs has been found by all of these permutations:
1) Make sure that all nodes included in the search have an associated menu link.
2) Make sure that the menu items with children have all been set to be expanded by default (so that you don't have to apply the "expand all children of this tree" option within the menu block).

If these settings will work for your site, then you can work around this issue.

carl.brown’s picture

Hi. I'm getting this same problem. I too have Menu Block installed. Unfortunately, the fix in #21 is unsuitable for my situation. Additionally, on my search results page, my embedded menu gets pretty broken too. I print my main menu using menu_tree() and on this particular page, the actual link text of all the top level links is removed, however the HTML (as in <ul>) structure and classes are preserved!

For info, following on from #17:
- "Perhaps the order of rendering the Menu Block matters..." my custom menu block (show siblings only of second level) is rendered after the main content (i'm using it as a side bar navigation)
- "...these notices only appear when the content I am finding in the search does not have a menu item associated with it" - This sounds about right too, as when the search result only includes pages that do have an associated menu item, the notices dissappear.
- "When you perform a search that returns the menu'd item you should see the additional "active-trail" classes added to the menu item." Bingo. Hadn't noticed this myself, but i'm getting exactly the same here.

Unfortunately, my knowledge doesn't extend far enough to be any help coding a fix for this, but good investigating @jasondecamp and thanks for looking into it @jhodgdon.

jhodgdon’s picture

Title: Notice: Trying to get property of non-object in node_page_title() (line 2073 of basepath/modules/node/node.module). » Use with Menu Block causes PHP notice and active trail problems
Status: Needs work » Active

I think that the fix to #1040002: Active trail being set incorrectly that I added to the 7.x development version of Search by Page a few days ago should fix the active trail issues that have been seen with Menu Block. If someone that has seen this problem can test, that would probably be useful.

I am still not sure about the property of non-object PHP notice that was originally reported, so I am leaving this issue open until that is resolved. If someone who was seeing this notice could verify that it is still happening with the latest Drupal 7.x and latest Search by Page, with Menu Block enabled, that could be helpful.

somanyfish’s picture

I do still get this error:

Notice: Trying to get property of non-object in node_page_title() (line 2075 of /var/www/html/modules/node/node.module).

I am running the dev version of Search by Page released on 9/23/2011, Drupal 7.8 and the dev version of Menu Block from 8/17/2011. I observe this behavior:

  1. When not logged in to site, visit www.example.com/search_pages/test which returns four pages of results.
  2. Dblog reports many "Trying to get property of non-object" errors.
  3. Remove menu block from search results page
  4. When not logged in to site, visit www.example.com/search_pages/test which returns four pages of results.
  5. Dblog reports no errors
  6. Add menu block back to search results page
  7. When not logged in to site, visit www.example.com/search_pages/test which returns four pages of results.
  8. Dblog reports many "Trying to get property of non-object" errors.
  9. When logged in to site, visit www.example.com/search_pages/test which returns four pages of results.
  10. Dblog reports *one* "Trying to get property of non-object" error.

I thought the last item was interesting -- logged in users only get one error when visiting the search results pages, where as anonymous users get a ton.

jhodgdon’s picture

Thanks for the specifics! I'll look into this as soon as I can.

jhodgdon’s picture

I have reproduced the behavior you are seeing, but I'm not sure why it's happening yet.

I've tracked it down to a function in menu.inc -- _menu_link_translate() is not getting $item['to_arg_functions'], which would normally auto-load the $node object. So it is not loading the node, and so it is not having an object to get the title from when it calls node_page_title(), which is generating that error.

But I don't yet know why this is the case... will investigate further, but unless I figure it out in the next few minutes, it may not be for a couple of weeks.

jhodgdon’s picture

No wait, that's not right. It's not the to_arg_functions, it's the load_functions that should be used... anyway I think the problem is in that function, just don't know where.

xrampage16’s picture

I am jumping on this thread in regards to the following error shown above, and how I was able to circumvent it

Notice: Trying to get property of non-object in node_page_title() (line 2075 of /var/www/html/modules/node/node.module).

On the site that I am working on, the menu is in the range of 500+ items, added based off of a migration from another CMS server. I have noticed this error popping up on pages that are added via hook_menu(), which have subsequent child pages. For instance, the example in question has content displayed here...

news-events-announcements/tw-news-views/mytw-weekly

with arguments of 2012, and 2011

news-events-announcements/tw-news-views/mytw-weekly/2012
news-events-announcements/tw-news-views/mytw-weekly/2011

to display more detailed information.

When visiting the child pages, and then accessing the original landing page of...

news-events-announcements/tw-news-views/mytw-weekly

I received 7 errors which correlated to all of the nodes drilling up to the root menu path, with them calling node_page_title with just the nid as the argument.

I was able to circumvent the issue, but adding a menu path to the arguments as well. While this might not be helpful in all situations, it leads me to believe that the issue stems from this menu item, while not being a node, preventing all of the other node items from being loaded as well.

For instance, if we had a hierarchy of...
node-1
--node-2
----node-3
----custom
------custom/arg

i believe the node's 1-3 will throw the page title error if you access custom/arg, and then custom.

A more permanent fix would be to edit line 586 of menu.inc, and perform a check to see if the item is a node_page_title, and to check to see if the argument is an object or not. If not, it would be the nid, and the nid can be loaded.

stixes’s picture

Status: Active » Needs review
StatusFileSize
new371 bytes

I get this error, as previously described, and decided to formulate a patch against 7.x .
I simply add a check in node_page_title, and load the object if I infer the argument is a nid:

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

I find this solution to work better then patching in menu.inc, since I need no string compare check against a fixed value.

Status: Needs review » Needs work

The last submitted patch, 1187776.patch, failed testing.

jhodgdon’s picture

RE #29 - Yes, you could hack core to fix this problem.

But the real root of the problem is that node_page_title() is always supposed to be receiving a fully-loaded $node object as its argument, because _menu_link_translate() is supposed to be making sure the $node object gets loaded. And it's not doing this, for some reason, when Search by Page is rendering pages internally to format search results, when the Menu Block module is being used.

What I'm not sure is why the malfunction is happening in _menu_link_translate under these circumstances.

jhodgdon’s picture

I took another look into this issue, and found some interesting things:
a) The Menu Blocks module does some additional caching of menu trails in its function
custom_menu_active_trail.inc :: __menu_block_set_menu_trail()
So if this module is going to work with Menu Blocks (not mess up its blocks), we'll probably need to do some more drupal_static_reset() stuff in Search by Page to get around it.

b) The PHP notices about node title are being generated when the function
menu_block.module :: menu_trail_build()
calls the core function
menu_tree_page_data()

  else {
    // Get the tree pruned for just the active trail.
    $tree = menu_tree_page_data($config['menu_name']);
  }

[This is called (somewhat indirectly) during the search execution, when it renders the page in search_by_page_page_content(), in these lines:

  foreach (module_implements('page_build') as $module) {
    $function = $module . '_page_build';
    $function($page);
  }

That, in turn, ends up calling menu_block_block_view() to render the menu block, and that calls that menu block function.]

More investigation still needed...

jhodgdon’s picture

Status: Needs work » Fixed

I just committed a fix for this issue to the 7.x development version of this module. Basically, Search by Page is now only rendering the content region blocks, so it should avoid all the problems in Menu Block when the menus in other regions are attempted to be rendered during processing of search results, which confuses Menu Block about which page it is on. On my test box, it definitely makes all the active trail and PHP notices problems go away with Menu Block. Hopefully it will work for everyone else too! :)

Status: Fixed » Closed (fixed)

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