tripal_ws.field_storage.inc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Implements hook_field_storage_info().
  4. */
  5. function tripal_ws_field_storage_info() {
  6. return array(
  7. 'field_tripal_ws_storage' => array(
  8. 'label' => t('Tripal Web Services'),
  9. 'description' => t('Retrieves fields data from a remote site using Tripal web services.'),
  10. 'settings' => array(),
  11. ),
  12. );
  13. }
  14. /**
  15. * Implements hook_field_storage_load().
  16. *
  17. * Responsible for loading the fields from the Chado database and adding
  18. * their values to the entity.
  19. */
  20. function tripal_ws_field_storage_load($entity_type, $entities, $age,
  21. $fields, $options) {
  22. $load_current = $age == FIELD_LOAD_CURRENT;
  23. global $language;
  24. $langcode = $language->language;
  25. foreach ($entities as $id => $entity) {
  26. // Iterate through the entity's fields so we can get the column names
  27. // that need to be selected from each of the tables represented.
  28. foreach ($fields as $field_id => $ids) {
  29. // By the time this hook runs, the relevant field definitions have been
  30. // populated and cached in FieldInfo, so calling field_info_field_by_id()
  31. // on each field individually is more efficient than loading all fields in
  32. // memory upfront with field_info_field_by_ids().
  33. $field = field_info_field_by_id($field_id);
  34. $field_name = $field['field_name'];
  35. $field_type = $field['type'];
  36. $field_module = $field['module'];
  37. // Get the instance for this field. If no instance exists then skip
  38. // loading of this field. This can happen when a field is deleted from
  39. // a bundle using the user UI form.
  40. // TODO: how to deal with deleted fields?
  41. $instance = field_info_instance($entity_type, $field_name, $entity->bundle);
  42. if (!$instance) {
  43. continue;
  44. }
  45. // Set an empty value by default, and let the hook function update it.
  46. $entity->{$field_name}['und'][0]['value'] = '';
  47. tripal_load_include_field_class($field_type);
  48. if (class_exists($field_type) && method_exists($field_type, 'load')) {
  49. $tfield = new $field_type($field, $instance);
  50. $tfield->load($entity);
  51. }
  52. } // end: foreach ($fields as $field_id => $ids) {
  53. } // end: foreach ($entities as $id => $entity) {
  54. }
  55. /**
  56. * Implements hook_field_storage_query().
  57. */
  58. function tripal_ws_field_storage_query($query) {
  59. }
  60. /**
  61. * Implements hook_field_storage_write().
  62. */
  63. function tripal_ws_field_storage_write($entity_type, $entity, $op, $fields) {
  64. }