From a3b2f287a56fe28776ac12ce6f69bc80f92dda08 Mon Sep 17 00:00:00 2001
From: OnkelTem <OnkelTem@239962.no-reply.drupal.org>
Date: Thu, 14 Mar 2013 14:44:59 +0400
Subject: [PATCH] Issue #1942732 by OnkelTem: WSOD when LEFT JOIN'ing
 entities' translations

---
 views/entity_translation_handler_field_label.inc   |    8 +++++++-
 ...ty_translation_handler_field_translate_link.inc |    8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/views/entity_translation_handler_field_label.inc b/views/entity_translation_handler_field_label.inc
index dd972d3..3127dd2 100644
--- a/views/entity_translation_handler_field_label.inc
+++ b/views/entity_translation_handler_field_label.inc
@@ -48,7 +48,9 @@ class entity_translation_handler_field_label extends views_handler_field {
     $ids = array();
     $ids_by_type = array();
     foreach ($values as $row) {
-      $ids_by_type[$this->get_value($row, 'entity_type')][] = $this->get_value($row, 'entity_id');
+      if ($entity_type = $this->get_value($row, 'entity_type')) {
+        $ids_by_type[$entity_type][] = $this->get_value($row, 'entity_id');
+      }
     }
     foreach ($ids_by_type as $type => $ids) {
       $this->entities[$type] = entity_load($type, $ids);
@@ -58,6 +60,10 @@ class entity_translation_handler_field_label extends views_handler_field {
   function render($values) {
     $entity_type = $this->get_value($values, 'entity_type');
     $entity_id = $this->get_value($values, 'entity_id');
+    // Check if entity is not empty
+    if (!$entity_id || !$entity_type) {
+      return NULL;
+    }
     $entity = $this->entities[$entity_type][$entity_id];
     // We could also use entity_label(), but since this we might want to let
     // the handler decide what's best to show.
diff --git a/views/entity_translation_handler_field_translate_link.inc b/views/entity_translation_handler_field_translate_link.inc
index bb7ba81..483db47 100644
--- a/views/entity_translation_handler_field_translate_link.inc
+++ b/views/entity_translation_handler_field_translate_link.inc
@@ -58,7 +58,9 @@ class entity_translation_handler_field_translate_link extends views_handler_fiel
     $ids = array();
     $ids_by_type = array();
     foreach ($values as $row) {
-      $ids_by_type[$this->get_value($row, 'entity_type')][] = $this->get_value($row, 'entity_id');
+      if ($entity_type = $this->get_value($row, 'entity_type')) {
+        $ids_by_type[$entity_type][] = $this->get_value($row, 'entity_id');
+      }
     }
     foreach ($ids_by_type as $type => $ids) {
       $this->entities[$type] = entity_load($type, $ids);
@@ -71,6 +73,10 @@ class entity_translation_handler_field_translate_link extends views_handler_fiel
   function render($values) {
     $type = $this->get_value($values, 'entity_type');
     $entity_id = $this->get_value($values, 'entity_id');
+    // Check if entity is not empty
+    if (!$entity_id || !$type) {
+      return NULL;
+    }
     $language = $this->get_value($values, 'language');
     $entity = $this->entities[$type][$entity_id];
     return $this->render_link($type, $entity_id, $entity, $language);
-- 
1.7.9.5

