You are here

function _drupalgap_add_term_data_to_entities in DrupalGap 7

Same name and namespace in other branches
  1. 7.2 drupalgap.module \_drupalgap_add_term_data_to_entities()
1 call to _drupalgap_add_term_data_to_entities()
drupalgap_services_request_postprocess_alter in ./drupalgap.module
Implements hook_services_request_postprocess_alter().

File

./drupalgap.module, line 728
A module to provide a bridge between Drupal websites and PhoneGap mobile applications.

Code

function _drupalgap_add_term_data_to_entities($controller, $args, &$result) {

  // Determine the entity type, or return if we don't need (or understand) how
  // to process it.
  $entity_type = null;
  $bundle = null;
  switch ($controller['callback']) {
    case '_comment_resource_index':
      $entity_type = 'comment';
      break;
    case '_node_resource_retrieve':
      $entity_type = 'node';
      $bundle = $result->type;
      break;
  }
  if (!$entity_type) {
    return;
  }
  if (is_array($result)) {

    // We have multiple results...
    foreach ($result as $i => $entity) {
      switch ($controller['callback']) {
        case '_comment_resource_index':
          $bundle = $entity->bundle;
          break;
        case '_node_resource_retrieve':
          $bundle = $entity->type;
          break;
      }
      $result[$i] = _drupalgap_add_term_data_to_entity($entity, $entity_type, $bundle);
    }
  }
  else {

    // We have a single result...
    $result = _drupalgap_add_term_data_to_entity($result, $entity_type, $bundle);
  }
}