after updating to beta 11 I'm getting log entries as follows:

Notice: Trying to get property of non-object in marinelli_preprocess_comment() (line 204 of /home/chaosgen/public_html/drupal/sites/all/themes/marinelli/template.php).

Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 177 of /home/chaosgen/public_html/drupal/includes/entity.inc).

I have narrowed it down to the function marinelli_preprocess_comment(&$vars) changes that occurred between beta10 and beta11, I think at least. I'm using the latest core, and recent (a couple of days old max) Rules and Entity API (not sure it matters). All is functioning, and my logs are clean if I revert to beta10.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mudtraining’s picture

Same issue here, after I applied this fix: http://drupal.org/node/1027804

Tobion’s picture

Same issue for me. But it only occurs sometimes. After I refresh the page the error disappears for some time again.

komal.savla’s picture

Hi,

Replace the following code in template.php (line 202) :

<?php
 if (isset($vars['user']->picture)) {
    // No.. I don't use style 
    if(!variable_get('user_picture_style')){
      $size = variable_get('user_picture_dimensions');
      $size = explode('x',$size);
      $user_image['width'] = $size[0];
    }
    else{
      //Yes... I use style
      if ($picture = file_load($vars['comment']->picture->fid)) {
        $user_image = image_get_info(image_style_path(variable_get('user_picture_style'), $picture->uri));
      }
    }
}
?>

with this :

<?php
if (isset($vars['user']->picture)) {
    // No.. I don't use style 
    if(!variable_get('user_picture_style')){
      $size = variable_get('user_picture_dimensions');
      $size = explode('x',$size);
      $user_image['width'] = $size[0];
    }
   else {
       if(isset($vars['comment']->picture->fid)) {  //Added this line
         //Yes... I use style
         if ($picture = file_load($vars['comment']->picture->fid)) {
          $user_image = image_get_info(image_style_path(variable_get('user_picture_style'), $picture->uri));
         }
      } //Added this line
   }
}
?>

Hope this helps.

Thanks,
Komal

RogueM’s picture

it does, thanks.

karilu_ec’s picture

Thanks a lot. it fixes the error.

dsdart’s picture

Fixed it for me too.

tedfeely’s picture

Even though I did not have the problem, I'm very pleased to see that there are people responding to Drupal and Marinelli needs.

So, thank you!

Lioz’s picture

Status: Active » Fixed

thanks komal pushed int he next release

Efremov_26’s picture

Title: marinelli_preprocess_comment issue in beta11 » Download banners

Hi!
Can not add banners to the site, tell me how! Thanks in advance!

Status: Fixed » Closed (fixed)

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

Daedalon’s picture

Before applying #3, I had the following error messages after viewing pages with comments:

  • Notice: Trying to get property of non-object in marinelli_preprocess_comment() (line 204 of /[siteroot]/sites/all/themes/marinelli/template.php).
  • Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of /[siteroot]/includes/entity.inc).

After applying I get the following instead in the next page after viewing a page with comments, regardless of whether the next page is front page or an admin page:

  • Notice: Undefined variable: image_width in include() (line 4 of /[siteroot]/sites/all/themes/marinelli/templates/comment.tpl.php).

The message comes as many times as there were comments, even if they were from the same author. This is the line being referred to:

<div style="margin-left:<?php print $image_width; ?>px;" class="comment-content">

The part after "div " and before "class" should be contained within an if that checks whether the $image_width is set and is the most efficient possible. Changing the line to be as follows the "margin-left" part was not anymore displayed in the HTML, but Drupal gave the same warning messages:

<div <?php if ($image_width): ?>style="margin-left:<?php print $image_width; ?>px;" <?php endif; ?>class="comment-content">

Tobion’s picture

In your example it needs to be "if (isset($image_width))" to check whether the variable exists.

Daedalon’s picture

Status: Closed (fixed) » Needs review

Thanks for the addition, Tobion.

I located the source of the error. It was a missing line in #3. Here's the correct code for template.php, line 192. No need for any changes to comment.tpl.php.

function marinelli_preprocess_comment(&$vars) {
  $vars['classes_array'][] = $vars['zebra'];
  $user_image = array('width' => 0);
  if (isset($vars['user']->picture)) {
    // No.. I don't use style
    if(!variable_get('user_picture_style')) {
      $size = variable_get('user_picture_dimensions');
      $size = explode('x',$size);
      $user_image['width'] = $size[0];
    }
    else {
      if(isset($vars['comment']->picture->fid)) {
        //Yes... I use style
        if ($picture = file_load($vars['comment']->picture->fid)) {
          $user_image = image_get_info(image_style_path(variable_get('user_picture_style'), $picture->uri));
        }
      }
    }
  }
  $vars['image_width'] = $user_image['width'] + 25;  // This line was missing
}
Daedalon’s picture

Lioz: Any chance you're putting a beta12 or an rc1 out any time soon? At least this issue seems to come up with every new install and upgrade and I keep redirecting people here to manually patch their beta11.

jimbaer’s picture

+1

thedosmann’s picture

Same fix worked here

JeffSheltren’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
636 bytes

I hit this same error, the fix posted here worked for me. I'm attaching it as a patch to make applying it easier.

Toddv’s picture

worked for me - thanks!!

Moonlight’s picture

Same problem ... It took some difficulties but eventually it works fine for me too.
Thanks!

twooten’s picture

Patch in #17 worked for me, thanks!

jbeall1369’s picture

Non-Coder besides HTML. How do I use a patch? Here is my error:

Notice: Trying to get property of non-object in marinelli_preprocess_comment() (line 204 of /home/dzired13/public_html/sites/all/themes/marinelli/template.php).
Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of /home/dzired13/public_html/includes/entity.inc).

jbeall1369’s picture

:(

Daedalon’s picture

I didn't use any patch. Replace a bit more than a dozen lines of code in template.php with a single copy-paste as per #13, including everything from "function" until the last "}" -- everything except the and tags that Drupal's forums required for displaying the code with the proper formatting.

Take backup of the original file first though. Each opening "{" in PHP needs to have exactly one closing "}", or your pages will show the dreaded White Page of Death, and even if this wasn't your first time editing PHP, it'd be easy to make a mistake with copy-paste code replace.

webmariner’s picture

Thanks to Daedalon for the fix in comment #13 above!

I've since noticed though that the left-margin style on the comment-content div is only being set to 25px when I log out.

I think it's using the width of the currently logged in user's profile image, instead of the image of the user who posted that comment.

I think line 195:
if (isset($vars['user']->picture)) {

should say:
if (isset($vars['comment']->picture)) {

Seems to fix the issue for me.

sifokl’s picture

Thanks a lot for #13

santiagobf’s picture

Hi,
Thanks a lot Daedalon, it work's for me!

Regards,
Santi

jasom’s picture

#17 worked for me. Don't forget clean all caches.

phofab’s picture

Following on from Comment 21, I am also a serious non coder and have no such knowledge. After a bit of deliberation I plucked up courage and made an attempt to substitute the defective code with solution #13, firstly on my Local/Host.
To assist others with little knowledge of the backend I offer the following steps:-
Locate where your Drupal program is stored, if on your Server it will be necessary to go into the Http/docs directory and look for a path something like:

sites/all/themes/marinelli/template.php

1. Back up your total Site on your local directory and/or the Directory on your Server.
2. Save template.php file to a temporary directory elsewhere on your computer
3. You now have a fall back position. DO NOT AMEND THIS FILE!
3(a) Open a new Directory, say “template amendment” and copy template.php into here and this becomes your working file.
4. Right click on template.php and select open with an editor like Dreamweaver or similar or possibly “notepad”
5. You should now see the script.
6. Go down and select/highlight lines 192 -210 (as described in #13), very carefully noting the exclusions- leave out first and last pieces of script ie: and
7. Go back to the display of #13 and copy the recommended text.
8. Back to Notepad and Paste the new text into the highlighted area
9. Save it back to your original file #(3a), in “template amendment”, overwrite the old file. Submit and overwrite the amended file to your Host.
10. Close, reopen your Browser, clearing the history cache
11. You will hopefully see the messages disappear and not the white screen of death as described above, it is not a good look.
12. Save this now working file up to your server and locate the template.php and overwrite it.

On my attempt I worked on my Local Directory and it worked well so that I went to the next step and repeated the steps on my ISP Server, unfortunately rather than use the working and adjusted template.php on my local host, I started afresh with the result that I saw the white screen of death appear on both the local host and server version. I hadn’t taken a copy of the template.php file on my own computer so that I couldn’t over write the converted file. I went up to the Server and implemented the replacement of my backup and the on line site Website came back. I transferred down to my computer the once again faulty template.php file to another Directory and made the changes above, when it could be seen that it was working, locally, it was transferred back to the Server and everything worked as it should.

The FIX as described has worked for me and I thank you all for setting up the necessary code.

makokis’s picture

#17
Posted by JeffSheltren, thanks it works for me