diff --git a/src/Plugin/search_api/datasource/ContentEntity.php b/src/Plugin/search_api/datasource/ContentEntity.php
index 23865b7..a8a4919 100644
--- a/src/Plugin/search_api/datasource/ContentEntity.php
+++ b/src/Plugin/search_api/datasource/ContentEntity.php
@@ -582,11 +582,26 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
   }
 
   /**
+   * Retrieves the entity from a search item.
+   *
+   * @param \Drupal\Core\TypedData\ComplexDataInterface $item
+   *   An item of this datasource's type.
+   *
+   * @return \Drupal\Core\Entity\EntityInterface|null
+   *   The entity object represented by that item, or NULL if none could be
+   *   found.
+   */
+  protected function getEntity(ComplexDataInterface $item) {
+    $value = $item->getValue();
+    return $value instanceof EntityInterface ? $value : NULL;
+  }
+
+  /**
    * {@inheritdoc}
    */
   public function getItemId(ComplexDataInterface $item) {
-    if ($item instanceof EntityAdapter) {
-      return $item->getValue()->id() . ':' . $item->getValue()->language()->getId();
+    if ($entity = $this->getEntity($item)) {
+      return $entity->id() . ':' . $entity->language()->getId();
     }
     return NULL;
   }
@@ -595,8 +610,8 @@ public function getItemId(ComplexDataInterface $item) {
    * {@inheritdoc}
    */
   public function getItemLabel(ComplexDataInterface $item) {
-    if ($item instanceof EntityAdapter) {
-      return $item->getValue()->label();
+    if ($entity = $this->getEntity($item)) {
+      return $entity->label();
     }
     return NULL;
   }
@@ -605,8 +620,8 @@ public function getItemLabel(ComplexDataInterface $item) {
    * {@inheritdoc}
    */
   public function getItemBundle(ComplexDataInterface $item) {
-    if ($item instanceof EntityAdapter) {
-      return $item->getValue()->bundle();
+    if ($entity = $this->getEntity($item)) {
+      return $entity->bundle();
     }
     return NULL;
   }
@@ -615,8 +630,7 @@ public function getItemBundle(ComplexDataInterface $item) {
    * {@inheritdoc}
    */
   public function getItemUrl(ComplexDataInterface $item) {
-    if ($item instanceof EntityAdapter) {
-      $entity = $item->getValue();
+    if ($entity = $this->getEntity($item)) {
       if ($entity->hasLinkTemplate('canonical')) {
         return $entity->toUrl('canonical');
       }
@@ -795,8 +809,7 @@ public function getViewModes($bundle = NULL) {
    */
   public function viewItem(ComplexDataInterface $item, $view_mode, $langcode = NULL) {
     try {
-      if ($item instanceof EntityAdapter) {
-        $entity = $item->getValue();
+      if ($entity = $this->getEntity($item)) {
         $langcode = $langcode ?: $entity->language()->getId();
         return $this->getEntityTypeManager()->getViewBuilder($this->getEntityTypeId())->view($entity, $view_mode, $langcode);
       }
