Hi,

Just installed the latest version available. Error below occur while using it with commerce product.

Notice: Undefined variable: node_id in lightbox2_field_formatter_view() (line 977 of /home/victori2/public_html/sites/all/modules/lightbox2/lightbox2.module).

but everything still work well... Any idea??

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

maxchock’s picture

error goes if i comment out line 977...

yukare’s picture

Version: 7.x-1.0-beta1 » 7.x-1.x-dev
Category: support » bug
Priority: Major » Normal

I will fix it. The error is that we get the node id (nid) when the lightbox is used on a node, but since commerce module may use other entity type, we do not get the nid. We need this id when using views to group the imagens on the page.

The fix will be set a default value for id and try to get it for each entity type.

maxchock’s picture

I see. One thing I notice is why Lightbox2 not working on the default content "Basic Page" ?? I wanted to generate the error on "Basic Page" but the image can only show original size on full content node and there is no lightbox feature. But it work on "Blog".

yukare’s picture

This is not the same issue, so please, open a new issue for it. For lightbox do not matter the content type, only the entity type, so provide more details about it. How you are using it? There is any public url i can access?

Thanks.

tomogden’s picture

Also getting this error using Lightbox on my profile2 pages. Please let us know when there is a patch or release we can download.

togsbayar’s picture

I also getting this error. And it looks bad because it shows many error messages, so I put some codes. Maybe it's not good. But at least errors gone for me.

Suggest me if you have any other good idea. What I changed is :
$element[$delta] = array(
'#theme' => 'lightbox2_image',
'#item' => $item,
'#lightbox_type' => $lightbox_type,
'#image_style' => $image_style,
'#lightbox_style' => $lightbox_style,
'#path' => $uri,
'#node_id' => $node_id,
'#field_name' => $field['field_name'],
);
This lines to :
if( isset($node_id) ){
$element[$delta] = array(
'#theme' => 'lightbox2_image',
'#item' => $item,
'#lightbox_type' => $lightbox_type,
'#image_style' => $image_style,
'#lightbox_style' => $lightbox_style,
'#path' => $uri,
'#node_id' => $node_id,
'#field_name' => $field['field_name'],
);
}
else{
$element[$delta] = array(
'#theme' => 'lightbox2_image',
'#item' => $item,
'#lightbox_type' => $lightbox_type,
'#image_style' => $image_style,
'#lightbox_style' => $lightbox_style,
'#path' => $uri,
'#field_name' => $field['field_name'],
);

SteffenR’s picture

The error occurs while having none 'node' Entity Types in the formatter_view - in combination with field_collection i also get the error message.
Setting $node_id to FALSE solved the issue for me - maybe we need some more validation here:

 $node_id = FALSE; 
  if ($entity_type == 'node') {
    $node_id = $entity->nid;
  }

SteffenR

bensti’s picture

same error #7 don't work for me

SteffenR’s picture

@bensti: have you already checked the values that are in the entity object ? You can use dsm($entity) (devel module) or print_r($entity) to have a look at all the values.

thirdboxcar’s picture

Same error as the above. I'm using it on a field_collection created with this module, if that makes a difference: http://drupal.org/project/field_collection

yukare’s picture

Status: Active » Fixed

I just commited a small fix for it, please test(wait for the next dev release) and report if you still have this issue.

Status: Fixed » Closed (fixed)

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

jalbrizio’s picture

I also Just installed 7.x-1.0-beta1 with the latest commerce product and im still seeing this issue.
I just commented out line 977 like in the first comment. and it works on my products.
I havent tested it anywhere else yet.

fehin’s picture

Status: Closed (fixed) » Active

I recently installed this module and I'm getting this same error on a user view.

laraz’s picture

Version: 7.x-1.x-dev » 7.x-1.0-beta1

same for me. version 7.x-1.0-beta1 with commerce product. I commented out line 977.

VladimirAus’s picture

Yep, error is still there with commerce.

Miao1994’s picture

I report the same PHP notice setting an image display field in article content (lightbox medium to original). No commerce product installed.

Miao1994’s picture

FileSize
131.71 KB
Elavarasan R’s picture

The error was fixed by doing as below

Add $node_id = 0; in lightbox2.module at line 960 or before the line
if ($entity_type == 'node') {
$node_id = $entity->nid;
}

tomogden’s picture

Status: Active » Reviewed & tested by the community

Using the Dev version from #11 fixes it for me.

I guess we are just waiting for this fix to come out in the next release?

ckukahiko’s picture

word. commenting out line 977 is working for me so far too.
thanks, maxchock!

bporter2387’s picture

Same happened to me. It turns out the entity type (for the commerce module) is 'commerce_product' instead of 'node'.. So I just added a 2nd conditional statement into there. Commenting out the line works too :P

  if ($entity_type == 'node') {
    $node_id = $entity->nid;
  }
  else if ($entity_type == 'commerce_product') {
    $node_id = $entity->product_id;
  }
  else {$node_id = NULL;}
a.milkovsky’s picture

I just define variable node_id. E.g. $node_id = '';

$node_id = '';
  if ($entity_type == 'node') {
    $node_id = $entity->nid;
  }
Narek’s picture

#23 works for.

I don't have this error on fields on node level, but I do when the field has been used for user, I think that is why its causing error.

Thanks a.milkovsky
Please let us know if this is the right way of fixing it.

lazly’s picture

Sorry guys, I dont want to be a jerk, but...
Its an 1 year old bug, with lots of solution from the developers and with easy reproduction.
Why doesnt commited it to base code? :(

mlopresti’s picture

This definitely needs to be fixed, but I think it should be in a way that works with all entities not just implicitly stated ones. That way we don't have to re-visit this every time we add a new entity.

tds2012’s picture

Hi, had the same issue and commented out line 977, it works now.

mindless_mind’s picture

My personal solution of problem.
Remove:

if ($entity_type == 'node') {
  $node_id = $entity->nid;
}

In line 977, replace

'#node_id' => $node_id,

with:

'#node_id' => $entity->identifier();

Should work for every entity type.

AlfTheCat’s picture

#27 worked for me but #28 produced an error (WSOD)

Error: syntax error, unexpected ';', expecting ')' in [..] line 977

mindless_mind’s picture

Sorry, my bad. There should be a comma instead of semicolon. I made a typo when writing post.
'#node_id' => $entity->identifier(),

djs070’s picture

My situation: same error when applying lightbox field formatter to image on a field collection.

Tried #30:
Fatal error: Call to undefined method stdClass::identifier() in ...sites/all/modules/lightbox2/lightbox2.module on line 977

Commenting out line 977 seems to work, though I'm anxious about other issues that this may cause.

EDIT: Just re-read the thread and found that $node_id is used in views. Have un-commented line 977 and changed 961:

  $node_id = false;
  if ($entity_type == 'node') {
    $node_id = $entity->nid;
  }
mindless_mind’s picture

FileSize
1.14 KB

Ok, I now see that I've made too many custom modifications in my own project, so my above changes won't work for you. In order to check why, I've created clean drupal installation and installed lightbox2 module from git. I attach patch with my changes. Notice that I added entity module dependency, because identifier() by itself is an entity class method. In patch I'm using entity_metadata_wrapper which is an entity module function. There is tendency to make nearly everything an entity, so I don't think that this additional dependency is a problem.

I created example node and user, with image field and it worked in both cases.

Applying patch:
Copy it to lightbox2 module directory.
In this directory invoke: git apply -v entity_identifier.patch

Can somebody confirm that this is working?

jason.fisher’s picture

did not apply for me.

mindless_mind’s picture

Did you have errors when applying patch? Are you sure that it made any changes in files? Just a moment ago I installed D7 fresh install, applied it and everything worked without scratch.

Hmmm... I have git version of lightbox2 module installed. Maybe this is required when applying patches?

Nevermind. I see that in the dev version it is fixed (commit 4757f78369fbda2cfb0da50eb3f614b79bf3b61b).

aaronmfisher86’s picture

#19 solved the issue for me!

Tokoh’s picture

#19 solved the issue for me too.

JeniferTucker’s picture

Subscribing.

D7 (7.20) clean install with Lightbox2 (7.x-1.0-beta1) installed and enabled.

Getting the same message orginally posted on 24 October 2011.

I have gone for #22 solution and applied to line 960 as using Lightbox2 with Commerce module as I have a multisite set up, one site for eCommerce.

Fixed and working.

Agree with #25 but understand the module developer may have other commitments.

http://drupal.org/project/lightbox2
Maintenance status: Seeking new maintainer
Development status: No further development

If the development status showed active, then I would have made a donation to encourage the developer for providing Lightbox2 for us all to use freely.

cjtriplett’s picture

#30 worked for me.

I'm not using the commerce module. The error was occurring on a panel page that replaces the default Node view. I tried adding the NID to the panel manually but this did not solve the error.

drasgardian’s picture

Version: 7.x-1.0-beta1 » 7.x-1.x-dev

The patch in #32 worked a treat for me, applied against 7.x-1.x-dev

ascii122’s picture

got this same problem using taxonomy term page with lightbox. Patch at #32 fixed it

5t4rdu5t’s picture

#32 also solved the problem for me. Thank you!!

yukare’s picture

Status: Reviewed & tested by the community » Fixed

The patch on #32 is commited: http://drupalcode.org/project/lightbox2.git/commit/0f07ed2
Thanks for mindless_mind for this.

Just one important thing, this adds a dependency from entity module, but it is necessary as it is impossible to get the id from all entity types in core/contrib without this.

Status: Fixed » Closed (fixed)

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

ragavendra_bn’s picture

Just put isset condition as below before $element...should work.......

970
971 if (!isset($node_id))
972 $node_id = '';
973
974 $element..............

Give me commit instructions, I can commit this to the next release....

Anonymous’s picture

Issue summary: View changes
Status: Closed (fixed) » Active

Getting this same error today(Jan 2014) with latest dev release. Commerce module installed.

mindless_mind’s picture

Are you sure that you have downloaded dev version..? :)

Anonymous’s picture

Hi @mindless_mind You were right, I was running 7.x-1.0-beta1. I just updated to the latest dev using drush and will report back on the error message status later today after I have a chance to watch the dlog for a while.

Anonymous’s picture

Updated to latest dev release and still getting error message in dblog:

page not found
Date Wednesday, February 19, 2014 - 13:49
User Anonymous (not verified)
Location ...modules/lightbox2/js/lightbox.js,q1388124812.pagespeed.jm.4ihZxm_Qi8.js
Referrer
Message ...modules/lightbox2/js/lightbox.js,q1388124812.pagespeed.jm.4ihZxm_Qi8.js
Severity warning
Hostname #########

mikeaja’s picture

Version: 7.x-1.x-dev » 7.x-1.0-beta1

Getting issue in 1.0-beta1 (bearing in mind this was reported 3 years ago).

I will try dev release, but it's a production site, and I'm not confident in using a dev release on an unmaintained module (only that I presume it's unmaintained given this is a 3 year old bug).

Alternatives to lightbox2 perhaps?

VM’s picture

Version: 7.x-1.0-beta1 » 7.x-1.x-dev

#42 indicates that the patch in #32 was applied to -dev on 06JUL13. Project page indicates that new beta hasn't been released that includes the patch. As such resetting the version to #39.

quotesBro’s picture

Status: Active » Fixed

marking as fixed again (#42)

Status: Fixed » Closed (fixed)

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

lughy’s picture

Hello,
at this time, #30 works for me (drupal 7.31 - lightbox2 7.x-1.0-beta1)

Wtower’s picture

Just for reference, if anyone upgrading from 7.x-1.0-beta1 to 7.x-1.x-dev gets an error:

'Fatal error: Call to undefined function entity_metadata_wrapper()'

make sure that you have the Entity API module up and enabled.