You are here

public function SearchApiEtDatasourceController::getMetadataWrapper in Search API Entity Translation 7.2

Creates a metadata wrapper for this datasource controller's type.

Parameters

mixed $item: Unless NULL, an item of the item type for this controller to be wrapped.

array $info: Optionally, additional information that should be used for creating the wrapper. Uses the same format as entity_metadata_wrapper().

Return value

EntityMetadataWrapper A wrapper for the item type of this data source controller, according to the info array, and optionally loaded with the given data.

Throws

SearchApiDataSourceException If any error state was encountered.

Overrides SearchApiEntityDataSourceController::getMetadataWrapper

See also

entity_metadata_wrapper()

File

includes/SearchApiEtDatasourceController.php, line 96
Contains the SearchApiEtDatasourceController class.

Class

SearchApiEtDatasourceController
Provides multilingual versions of all entity types.

Code

public function getMetadataWrapper($item = NULL, array $info = array()) {

  // Since this is usually called with a "property info alter" callback
  // already in place (and only one value is allowed), we have to call
  // the existing callback from within our own callback to make it work.
  $property_info_alter = isset($info['property info alter']) ? $info['property info alter'] : NULL;
  $callback = new SearchApiEtPropertyInfoAlter($property_info_alter);
  $info['property info alter'] = array(
    $callback,
    'propertyInfoAlter',
  );

  // If the item isn't the object and a multilingual id is provided
  // extract the entity id to load and wrap the entity.
  if (SearchApiEtHelper::isValidItemId($item)) {
    $item = SearchApiEtHelper::splitItemId($item, SearchApiEtHelper::ITEM_ID_ENTITY_ID);
  }
  $wrapper = entity_metadata_wrapper($this->entityType, $item, $info);

  // If the item's language is set, let's set it on all wrapper fields,
  // so that their translated values get indexed.
  if (!empty($item->search_api_language)) {

    // Set language on the wrapper as a whole.
    $wrapper
      ->language($item->search_api_language);

    // Also try to set language on all wrapper fields, recursively.
    if (!empty($item->search_api_index)) {
      $this
        ->setLanguage($wrapper, $item->search_api_index->options['fields'], $item->search_api_language);
    }
  }
  return $wrapper;
}