You are here

public function Item::getOriginalObject in Search API 8

Returns the original complex data object this Search API item is based on.

Parameters

bool $load: (optional) If TRUE, the object will be loaded if necessary. Otherwise, NULL will be returned if the object isn't available.

Return value

\Drupal\Core\TypedData\ComplexDataInterface|null The wrapped object if it was previously set or could be loaded. NULL if it wasn't set previously and $load is FALSE.

Throws

\Drupal\search_api\SearchApiException Thrown if $load is TRUE but the object could not be loaded.

Overrides ItemInterface::getOriginalObject

3 calls to Item::getOriginalObject()
Item::getAccessResult in src/Item/Item.php
Checks whether a user has permission to view this item.
Item::getFields in src/Item/Item.php
Returns the item's fields.
Item::getLanguage in src/Item/Item.php
Retrieves the item language.

File

src/Item/Item.php, line 201

Class

Item
Provides a default implementation for a search item.

Namespace

Drupal\search_api\Item

Code

public function getOriginalObject($load = TRUE) {
  if (!isset($this->originalObject) && $load) {
    $this->originalObject = $this->index
      ->loadItem($this->itemId);
    if (!$this->originalObject) {
      throw new SearchApiException('Failed to load original object ' . $this->itemId);
    }
  }
  return $this->originalObject;
}