Hi, I was perusing my site as a non-admnistrator and while clicking around I received this message twice, then it disappeared.

Notice: Trying to get property of non-object in widgets_build_cache_cid() (line 1200 of /home/corpora1/public_html/sites/all/modules/widgets/widgets.module).

I do not have Widget Service Links enabled.

Any help would be great, I don't want anonymous visitors to be freaked out by random error messages on the site :)

thanks.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

TomDude48’s picture

Status: Active » Postponed (maintainer needs more info)

Can you tell me the path of the page you were on?

pverrier’s picture

FileSize
771 bytes

I have the same kind of notice in another context :
" Notice : Trying to get property of non-object dans widgets_get_context_author_uid() (ligne 1300 dans C:\wamp\www\rdj3\sites\all\modules\widgets\widgets.module). "

I created some views in order to show data in a "user space" : /user/%/publications (list of the nodes he published), /user/%/comments, and so on (where % is a UID).
I have this notice only in these pages, the concerned code being :

function widgets_get_context_author_uid($context = array()) {
  $uid = '';    
  if (isset($context['node']->uid)) {
    $uid = $context['node']->uid; 
  }
  elseif ((arg(0) == 'node') && is_numeric(arg(1))) {         
    $uid = menu_get_object()->uid;
  }
  elseif (arg(0) == 'user' && is_numeric(arg(1))) {
    $uid = menu_get_object('user', 1)->uid;
  }	
  drupal_alter('widgets_context_author_uid', $uid, $context);
  return $uid;
}

especially line 1300 because arg(0) == 'user' && is_numeric(arg(1)) is true, and menu_get_object('user', 1) is null in this context.

I think something is missing here :

  1. either checking if the path has only 2 components (user/%)
  2. or checking if menu_get_object() returns null

Since the user object seems to be loaded in other contexts than user/% (like user/%/socialmedia), the second solution is better.

In my case, directly using arg(1) instead of menu_get_object() would do the trick, but I think it's better to implement my special needs in the alter function.

I suggest a patch below, also covering the node context case few lines above. Perhaps will be a solution for @flock since widgets_build_cache_cid() calls widgets_get_context_author_uid() (?)...

dddave’s picture

Status: Postponed (maintainer needs more info) » Needs review

Correcting status (don't have the issue btw).

vaibhavroys’s picture

where should i paste this patch please give a brief explanation
.

dddave’s picture

Here is a good tutorial about applying patches: http://drupal.org/node/620014

pverrier’s picture

Version: 7.x-1.0-beta3 » 7.x-1.x-dev
FileSize
787 bytes

I made the first patch with svn.
This one is made with git on current dev version.

pverrier’s picture

Version: 7.x-1.x-dev » 7.x-1.0-beta5
FileSize
44.4 KB

Modified file from beta5 will be easier to use directly...

rsvelko’s picture

the patch from #6 fixed it for me. D7, php 5.3

the patch code seems quite logical.

TomDude48’s picture

patch applied. Thanks pverrier!

pverrier’s picture

You're welcome! :)

TomDude48’s picture

Status: Needs review » Closed (fixed)

No more error reports, assuming fixed.