tripal_ws.api.inc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * @file
  4. *
  5. * This file provides the Tripal Web Services API: a set of functions for
  6. * interacting with the Tripal Web Services.
  7. */
  8. /**
  9. * @defgroup tripal_ws_api Tripal Web Services
  10. *
  11. * @ingroup tripal_api
  12. * The Tripal Web Services API provides a set of functions for interacting
  13. * with the Tripal Web Services.
  14. *
  15. */
  16. /**
  17. * Adjust the values of a field for display in web services.
  18. *
  19. * This hook should be used sparingly. It is meant primarily to adjust 3rd
  20. * Party (non Tripal) fields so that they work with web
  21. * services. The caller should adjust the $items array as needed.
  22. * This change only affects the value displayed in web services. Web services
  23. * expect that every field have a 'value' element for each of the items. If a
  24. * field for some reason does not have a 'value' element then this hook will
  25. * allow setting of that element.
  26. *
  27. * @param $items
  28. * The list of items for the field.
  29. * @param $field
  30. * The field array.
  31. * @param $instance
  32. * The field instance array.
  33. *
  34. * @ingroup tripal_ws_api
  35. */
  36. function hook_tripal_ws_value(&$items, $field, $instance) {
  37. // The image module doesn't properly set the 'value' field, so we'll do it
  38. // here.
  39. if($field['type'] == 'image' and $field['module'] == 'image') {
  40. foreach ($items as $delta => $details) {
  41. if ($items[$delta] and array_key_exists('uri', $items[$delta])) {
  42. $items[$delta]['value']['schema:url'] = file_create_url($items[$delta]['uri']);
  43. }
  44. }
  45. }
  46. }