You are here

function clients_drupal_clients_fields in Web Service Clients 7

Same name and namespace in other branches
  1. 6 backends/clients_drupal/clients_drupal.module \clients_drupal_clients_fields()

Implementation of hook_clients_fields - refactor as inc file? Allows us to get field for a specific resource. Default fields are set at the connection type level here and additional custom field will be defined per resource (@todo). This will allow adding of remote cck fields (for example) for a specific resource (e.g. a certain view). This function will need to aggregate these with the base ones. (Otherwise this function is used to return all available fields.)

File

backends/clients_drupal/clients_drupal.module, line 216
Drupal Services plugin for Clients module

Code

function clients_drupal_clients_fields($resource = NULL) {
  if ($resource) {
    $connection = clients_connection_load((int) $resource->cid);
    if ($connection->type != 'drupal_services') {
      return;
    }
    $result = clients_call($resource);
    if (isset($result[0]->data[0])) {
      $fields = array_keys($result[0]->data[0]);
      $fieldset = array();
      foreach ($fields as $field) {
        $fieldset[$field] = array(
          'name' => $field,
          'description' => '',
        );
      }
      return $fieldset;
    }
    else {
      drupal_set_message('No fields were returned');
      return;
    }
  }

  // need to define behaviour if no resource specified - should this display:
  // - no fields
  // - a preset list of fields (from each service module)
  // - all possible fields from currently defined resources
  return array();
}