You are here

function _sheetnode_ajax_field in Sheetnode 5

Same name and namespace in other branches
  1. 6 sheetnode.module \_sheetnode_ajax_field()
  2. 7.2 sheetnode.module \_sheetnode_ajax_field()
  3. 7 sheetnode.module \_sheetnode_ajax_field()
1 string reference to '_sheetnode_ajax_field'
sheetnode_menu in ./sheetnode.module
Implementation of hook_menu().

File

./sheetnode.module, line 639

Code

function _sheetnode_ajax_field($oid = NULL, $entity = NULL, $field = NULL) {
  if (!$oid) {
    $oid = $_REQUEST['oid'];
  }
  if (!$entity) {
    $entity = $_REQUEST['entity'];
  }
  if (!$field) {
    $field = $_REQUEST['field'];
  }
  if (function_exists($entity . '_load')) {
    $object = call_user_func($entity . '_load', $oid);
    $value = NULL;
    if ($object) {

      // Try CCK field.
      if ($entity == 'node' && module_exists('content')) {
        $field_info = content_fields($field, $object->type);
        if ($field_info) {
          $field_info['display_settings']['label']['format'] = 'hidden';
          $value = content_view_field($field_info, $object, FALSE, TRUE);
        }
      }

      // Try rendered node field.
      if (!$value && $entity == 'node') {
        $node = drupal_clone($object);
        $node = node_build_content($node);
        if (isset($node->content[$field])) {
          $value = drupal_render($node->content[$field]);
        }
      }

      // Try raw object field.
      if (!$value && isset($object->{$field})) {
        if (is_object($object->{$field}) || is_array($object->{$field})) {
          $value = print_r($object->{$field}, TRUE);
        }
        else {
          $value = $object->{$field};
        }
      }

      // If found, send it back.
      if ($value) {
        _sheetnode_json(array(
          'type' => is_numeric($value) ? 'n' : 'th',
          'value' => $value,
        ));
        exit;
      }
    }
  }
  _sheetnode_json(array(
    'value' => '',
    'type' => 'e#NAME?',
  ));
  exit;
}