Skip to content

Instantly share code, notes, and snippets.

@xuxucode
Created February 13, 2018 03:15
Show Gist options
  • Save xuxucode/764456ebe72fc12849b67df03c7fb2c0 to your computer and use it in GitHub Desktop.
Save xuxucode/764456ebe72fc12849b67df03c7fb2c0 to your computer and use it in GitHub Desktop.
diff --git a/src/Entity/CommerceContentEntityBase.php b/src/Entity/CommerceContentEntityBase.php
index 026a79c4f..3e62a878e 100644
--- a/src/Entity/CommerceContentEntityBase.php
+++ b/src/Entity/CommerceContentEntityBase.php
@@ -23,7 +23,7 @@ public function getTranslatedReferencedEntities($field_name) {
*/
public function getTranslatedReferencedEntity($field_name) {
$referenced_entities = $this->getTranslatedReferencedEntities($field_name);
- return reset($referenced_entities);
+ return reset($referenced_entities) ?: NULL;
}
/**
diff --git a/src/Entity/CommerceContentEntityInterface.php b/src/Entity/CommerceContentEntityInterface.php
index d776d1109..387411dea 100644
--- a/src/Entity/CommerceContentEntityInterface.php
+++ b/src/Entity/CommerceContentEntityInterface.php
@@ -27,7 +27,7 @@ public function getTranslatedReferencedEntities($field_name);
* The entity reference field name.
*
* @return \Drupal\Core\Entity\ContentEntityInterface
- * The entity.
+ * The entity, or NULL if not found.
*/
public function getTranslatedReferencedEntity($field_name);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment