warning: Invalid argument supplied for foreach() in sites/all/modules/realname/realname.module on line 305.

Happens when http://drupal.org/project/fb is enabled.

Comments

nancydru’s picture

Status: Active » Postponed (maintainer needs more info)

I don't see a "foreach" anywhere near line 305.

nadams84’s picture

I'm getting the same problem but on line 325 'using latest dev version on 27/03/10 or 03/27/10', its the "foreach" statement within the;

function realname_theme_registry_alter......etc....

block of code.

Help appreciated, any ideas??

whan’s picture

I'm getting the same error.

Juan C’s picture

Same warning appear upon updating fb (drupal for facebook):

Invalid argument supplied for foreach() in sites/all/modules/realname/realname.module on line 325

whan’s picture

Status: Postponed (maintainer needs more info) » Active
msti’s picture

Hi!
I get the same error.
What info should I provide you with?

nancydru’s picture

Status: Active » Needs review
StatusFileSize
new1.12 KB

Try this patch. I'm not sure that fb is correct, but this will get around it.

msti’s picture

The error was random so I canot be certain, but looks like the patch is working.
Thanks!!

nancydru’s picture

Can someone else RTBC this?

gapple’s picture

StatusFileSize
new1011 bytes
new1014 bytes

It sounds like FB may be removing the array element, my guess is so that it can pull in its own images to override core's.

To be strict, the if statement will throw an undefined index error instead of the invalid argument in the foreach; using empty() to check the variable should remedy that.

The patch really doesn't change any functionality, so I don't see any issues. My only thought is that the code could potentially be cleaned up, optimizing or removing the foreach.
The first patch retains the foreach, but uses array_keys() to find only those keys that match the desired value in order to loop through. Potentially an unneeded optimization if there are few preprocess functions defined (as I assume is the case).
The second patch does away with the foreach completely under the assumption that 'template_preprocess_user_picture' will only exist in the array once.

brisath’s picture

Subscribing. Same problem.

Cynthia Ewer’s picture

Subscribing.

dave reid’s picture

Title: Realname error when fb (facebook connect) is enabled » Overriding theme registry without providing all the properties can cause problems in other modules
Project: Real Name » Drupal for Facebook
Version: 6.x-1.x-dev » 6.x-3.x-dev
Component: Code » Facebook Connect
Status: Needs review » Needs work

fb_connect.module should not be removing them, it should be setting $theme_registry['user_picture']['preprocess functions'] = array() rather than leaving a NULL value.

Dave Cohen’s picture

I don't think that's the real problem. I think the correct fix is to weight username.module lighter than fb_connect.module so that it's hook_theme_registry_alter runs first. Otherwise it is adding a preprocess function to the wrong theme function.

aaron.r.carlton’s picture

subscribing. i changed the module weight for user to -3, lighter than fb at -2 and cleared my cache, but still got the error.

Dave Cohen’s picture

Its the realname module that has to be lighter.

geosmaga’s picture

working for me :-) realname must be lighter then fb (all fb modules enabled) and the issue is gone. Thanks

vkareh’s picture

Status: Needs work » Needs review
StatusFileSize
new898 bytes

I made a quick patch for those that need to update the weight of the RealName module.

This fixes the issue with the FB module, but it may also allows RealName to play nicer with other modules that override the theme registry, so feel free to move to the RealName queue if it's marked RTBC.

I used realname-6.x-1.x-dev (2010-Dec-10) and fb-6.x-3.0-rc7

socialnicheguru’s picture

Issue tags: +realname integration

just adding realname tag. should the maintainer of that module be made aware of this?

nancydru’s picture

Project: Drupal for Facebook » Real Name
Version: 6.x-3.x-dev » 6.x-1.x-dev
Component: Facebook Connect » Miscellaneous

She is. This patch is inappropriate for the FB issue queue.

dave reid’s picture

Project: Real Name » Drupal for Facebook
Version: 6.x-1.x-dev » 6.x-3.x-dev
Priority: Normal » Major
Status: Needs review » Needs work

Sorry but I'm going to have to push back on fb_connect.module for this. Use Devel module and then go to devel/theme/registry - every *single* theme hook has at least 'preprocess functions' => array('theme_preprocess') - it's very much wrong to remove this.

Even _theme_process_registry() has this:

      // Check for default _preprocess_ functions. Ensure arrayness.
      if (!isset($info['preprocess functions']) || !is_array($info['preprocess functions'])) {
        $info['preprocess functions'] = array();

which gets run before the alter hook in _theme_build_registry()

So in summary, it is wrong to do the following in fb_connect.module without also providing the 'default' values expected of a theme registry item:

    $theme_registry['user_picture'] = array(
      'arguments' => array('account' => NULL),
      'function' => 'fb_connect_theme_user_picture_override',
      'type' => 'module',
    );
dave reid’s picture

Although definitely realname is doing a separate issue wrong by adding it's preprocess hook via theme_registry_alter() rather than just declaring its function as 'realname_preprocess_user_picture' so that it *automatically* gets called - no alter necessary.

dave reid’s picture

Filed #1068666: No need to use hook_theme_registry_alter() to override template_preprocess_user_picture() with Realname, but this is still a "best practice" fix for Drupal for Facebook.

Dave Cohen’s picture

Component: Miscellaneous » Facebook Connect
Priority: Major » Normal

I'm willing to make a change, but what are these "'default' values expected of a theme registry item"?