Posted by maxchock on October 24, 2011 at 7:59am
37 followers
| Project: | Lightbox2 |
| Version: | 7.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | reviewed & tested by the community |
Issue Summary
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??
| Attachment | Size |
|---|---|
| error.jpg | 92.48 KB |
Comments
#1
error goes if i comment out line 977...
#2
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.
#3
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".
#4
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.
#5
Also getting this error using Lightbox on my profile2 pages. Please let us know when there is a patch or release we can download.
#6
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'],
);
#7
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:
<?php$node_id = FALSE;
if ($entity_type == 'node') {
$node_id = $entity->nid;
}
?>
SteffenR
#8
same error #7 don't work for me
#9
@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.
#10
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
#11
I just commited a small fix for it, please test(wait for the next dev release) and report if you still have this issue.
#12
Automatically closed -- issue fixed for 2 weeks with no activity.
#13
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.
#14
I recently installed this module and I'm getting this same error on a user view.
#15
same for me. version 7.x-1.0-beta1 with commerce product. I commented out line 977.
#16
Yep, error is still there with commerce.
#17
I report the same PHP notice setting an image display field in article content (lightbox medium to original). No commerce product installed.
#18
#19
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;
}
#20
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?
#21
word. commenting out line 977 is working for me so far too.
thanks, maxchock!
#22
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;}
#23
I just define variable node_id. E.g. $node_id = '';
<?php$node_id = '';
if ($entity_type == 'node') {
$node_id = $entity->nid;
}
?>
#24
#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.
#25
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? :(
#26
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.
#27
Hi, had the same issue and commented out line 977, it works now.
#28
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.
#29
#27 worked for me but #28 produced an error (WSOD)
Error: syntax error, unexpected ';', expecting ')' in [..] line 977#30
Sorry, my bad. There should be a comma instead of semicolon. I made a typo when writing post.
'#node_id' => $entity->identifier(),#31
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 977Commenting 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;
}
#32
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?
#33
did not apply for me.
#34
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).
#35
#19 solved the issue for me!
#36
#19 solved the issue for me too.
#37
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.
#38
#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.
#39
The patch in #32 worked a treat for me, applied against 7.x-1.x-dev
#40
got this same problem using taxonomy term page with lightbox. Patch at #32 fixed it