diff --git a/src/Plugin/search_api/datasource/ContentEntity.php b/src/Plugin/search_api/datasource/ContentEntity.php
index 8d5993b..6474d32 100644
--- a/src/Plugin/search_api/datasource/ContentEntity.php
+++ b/src/Plugin/search_api/datasource/ContentEntity.php
@@ -585,8 +585,8 @@ class ContentEntity extends DatasourcePluginBase {
    * {@inheritdoc}
    */
   public function getItemId(ComplexDataInterface $item) {
-    if ($item instanceof EntityAdapter) {
-      return $item->getValue()->id() . ':' . $item->getValue()->language();
+    if ($entity = $this->getEntity($item)) {
+      return $entity->id() . ':' . $entity->language();
     }
     return NULL;
   }
@@ -595,8 +595,8 @@ class ContentEntity extends DatasourcePluginBase {
    * {@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 +605,8 @@ class ContentEntity extends DatasourcePluginBase {
    * {@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 +615,7 @@ class ContentEntity extends DatasourcePluginBase {
    * {@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 +794,7 @@ class ContentEntity extends DatasourcePluginBase {
    */
   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);
       }
@@ -1045,4 +1043,21 @@ class ContentEntity extends DatasourcePluginBase {
     return $indexes;
   }
 
+  /**
+   * Retrieves the entity from datasource value.
+   *
+   * @param \Drupal\Core\TypedData\ComplexDataInterface $item
+   *   An item of this datasource's type.
+   *
+   * @return \Drupal\Core\Entity\EntityInterface|null
+   *   An entity object from datasource, or NULL if item value does not contain
+   *   a entity instance.
+   */
+  protected function getEntity(ComplexDataInterface $item) {
+    if ($item->getValue() instanceof EntityInterface) {
+      return $item->getValue();
+    }
+    return NULL;
+  }
+
 }
