function _sheetnode_ajax_field in Sheetnode 6
Same name and namespace in other branches
- 5 sheetnode.module \_sheetnode_ajax_field()
- 7.2 sheetnode.module \_sheetnode_ajax_field()
- 7 sheetnode.module \_sheetnode_ajax_field()
AJAX function to return a field value.
1 string reference to '_sheetnode_ajax_field'
- sheetnode_menu in ./
sheetnode.module - Implementation of hook_menu().
File
- ./
sheetnode.module, line 1019
Code
function _sheetnode_ajax_field($oid = NULL, $entity_type = NULL, $field = NULL) {
if (!$oid) {
$oid = $_REQUEST['oid'];
}
if (!$entity_type) {
$entity_type = $_REQUEST['entity_type'];
}
if (!$field) {
$field = $_REQUEST['field'];
}
$value = NULL;
$entity = _sheetnode_load_entity($entity_type, $oid);
if ($entity) {
// Try CCK field.
if ($entity_type == 'node' && module_exists('content')) {
$field_info = content_fields($field, $entity->type);
if ($field_info) {
if (!content_access('view', $field_info, NULL, $entity)) {
drupal_json(array(
'value' => '',
'type' => 'e#NAME?',
));
exit;
}
$field_info['display_settings']['label']['format'] = 'hidden';
$value = content_view_field($field_info, $entity, FALSE, TRUE);
}
}
// Try rendered node field.
if (!$value && $entity_type == 'node') {
$node = drupal_clone($entity);
$node = node_build_content($node);
if (isset($node->content[$field])) {
$value = drupal_render($node->content[$field]);
}
}
// Try raw object field.
if (!$value && isset($entity->{$field})) {
if (is_object($entity->{$field}) || is_array($entity->{$field})) {
$value = print_r($entity->{$field}, TRUE);
}
else {
$value = $entity->{$field};
}
}
// If found, send it back.
if ($value) {
drupal_json(array(
'type' => is_numeric($value) ? 'n' : 'th',
'value' => $value,
));
exit;
}
}
drupal_json(array(
'value' => '',
'type' => 'e#NAME?',
));
exit;
}