datasource_translated_entity.inc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. $properties = $wrapper->getPropertyInfo();
  28. foreach ($properties as $key=>$property) {
  29. if (isset($property['type']) && $property['type'] == 'taxonomy_term') {
  30. $wrapper->$key->language($target_language);
  31. }
  32. }
  33. return $wrapper;
  34. }
  35. }
  36. return parent::getMetadataWrapper($item, $info);
  37. }
  38. }