You are here

function node_service_get in Services 6.2

Same name and namespace in other branches
  1. 6 services/node_service/node_service.inc \node_service_get()
  2. 7 services/node_service/node_service.inc \node_service_get()

Returns a specified node.

Parameters

$nid: Number. The node ID.

$fields: Array (optinonal). The node fields needed. If its empty, all fields will be returned

Return value

Object. The node object with all wanted fields.

1 string reference to 'node_service_get'
node_service_service in services/node_service/node_service.module
Implementation of hook_service().

File

services/node_service/node_service.inc, line 19
Link general node functionalities to services module.

Code

function node_service_get($nid, $fields = array()) {
  global $user;
  $node = node_load(array(
    'nid' => $nid,
  ));
  if ($node) {

    // Apply field level content permissions
    if (module_exists('content') && variable_get('services_use_content_permissions', FALSE)) {
      $content_fields = content_fields(NULL, $node->type);
      foreach ($content_fields as $field_name => $field_info) {
        if (isset($node->{$field_name})) {
          $access = module_invoke_all('field_access', 'view', $field_info, $user, $node);
          if (in_array(FALSE, $access)) {
            unset($node->{$field_name});
          }
        }
      }
    }
    $result = services_node_load($node, $fields);
  }
  else {
    $result = services_error(t('Could not find the node.'), 404);
  }
  return $result;
}