callback_add_url.inc 728 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. /**
  3. * Search API data alteration callback that adds an URL field for all items.
  4. */
  5. class SearchApiAlterAddUrl extends SearchApiAbstractAlterCallback {
  6. public function alterItems(array &$items) {
  7. foreach ($items as $id => &$item) {
  8. $url = $this->index->datasource()->getItemUrl($item);
  9. if (!$url) {
  10. $item->search_api_url = NULL;
  11. continue;
  12. }
  13. $item->search_api_url = url($url['path'], array('absolute' => TRUE) + $url['options']);
  14. }
  15. }
  16. public function propertyInfo() {
  17. return array(
  18. 'search_api_url' => array(
  19. 'label' => t('URI'),
  20. 'description' => t('An URI where the item can be accessed.'),
  21. 'type' => 'uri',
  22. ),
  23. );
  24. }
  25. }