datasource_translated_entity.inc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. class EntityTranslationDataSourceController extends SearchApiEntityDataSourceController {
  3. /**
  4. * Get a metadata wrapper for the item type of this data source controller.
  5. *
  6. * @param $item
  7. * Unless NULL, an item of the item type for this controller to be wrapped.
  8. * @param array $info
  9. * Optionally, additional information that should be used for creating the
  10. * wrapper. Uses the same format as entity_metadata_wrapper().
  11. *
  12. * @return EntityMetadataWrapper
  13. * A wrapper for the item type of this data source controller, according to
  14. * the info array, and optionally loaded with the given data.
  15. *
  16. * @see entity_metadata_wrapper()
  17. */
  18. public function getMetadataWrapper($item = NULL, array $info = array()) {
  19. if (is_array($info['property info alter'])) {
  20. $index = reset($info['property info alter']);
  21. $target_language = $index->options['entity_translation_language'];
  22. if ($target_language != ENTITY_TRANSLATION_SEARCH_API_NO_TRANSLATION) {
  23. // This may not be really needed.
  24. $info['langcode'] = $target_language;
  25. $wrapper = parent::getMetadataWrapper($item, $info);
  26. $wrapper->language($target_language);
  27. return $wrapper;
  28. }
  29. }
  30. return parent::getMetadataWrapper($item, $info);
  31. }
  32. }