diff --git a/lightbox2.info b/lightbox2.info
index fca1793..7ea4e37 100644
--- a/lightbox2.info
+++ b/lightbox2.info
@@ -4,6 +4,8 @@ description = Enables Lightbox2 for Drupal
 core = 7.x
 package = User interface
 
+dependencies[] = entity
+
 files[] = lightbox2.install
 files[] = lightbox2.module
 files[] = lightbox2.formatter.inc
diff --git a/lightbox2.module b/lightbox2.module
index 4bfc6d9..8e0baef 100644
--- a/lightbox2.module
+++ b/lightbox2.module
@@ -958,12 +958,7 @@ function lightbox2_field_formatter_view($entity_type, $entity, $field, $instance
     $lightbox_style = NULL;
   }
 
-  if ($entity_type == 'node') {
-    $node_id = $entity->nid;
-  } 
-  else {
-    $node_id = 0;
-  }
+  $wrapper = entity_metadata_wrapper($entity_type, $entity);
 
   foreach ($items as $delta => $item) {
     $uri = array(
@@ -977,7 +972,7 @@ function lightbox2_field_formatter_view($entity_type, $entity, $field, $instance
       '#image_style' => $image_style,
       '#lightbox_style' => $lightbox_style,
       '#path' => $uri,
-      '#node_id' => $node_id,
+      '#node_id' => $wrapper->getIdentifier(),
       '#field_name' => $field['field_name'],
     );
   }
