function _cmis_sync_node_field_value in CMIS API 6.2
Utility that gets/sets node field value. Only supports regular, text and filefield fields types.
2 calls to _cmis_sync_node_field_value()
- _cmis_sync_cmis_to_drupal_prepare in cmis_sync/
cmis_sync.module - Maps a cmis_object to a drupal node.
- _cmis_sync_drupal_to_cmis_prepare in cmis_sync/
cmis_sync.module - Maps a drupal node to a cmis_object
File
- cmis_sync/
cmis_sync.module, line 395
Code
function _cmis_sync_node_field_value(&$node, $field_name, $field_value = NULL, $context = array()) {
$content_type = content_types($node->type);
$value = NULL;
if (array_key_exists($field_name, $content_type['fields'])) {
// CCK field
$content_field = $node->{$field_name};
switch ($content_type['fields'][$field_name]['type']) {
case 'filefield':
if ($field_value == NULL) {
$value = file_get_contents($content_field[0]['filepath']);
}
else {
if (is_array($node->{$field_name})) {
// Update drupal file node on filesystem
file_put_contents($content_field[0]['filepath'], $field_value);
}
else {
if (array_key_exists('cmis', $context)) {
// Create file
$file_drupal_path = file_directory_path() . '/cmis_' . basename($context['cmis']->properties['ObjectId']) . '_' . $context['cmis']->title;
file_put_contents($file_drupal_path, $field_value);
// Create file field
$file = new stdClass();
$file->filename = basename($file_drupal_path);
$file->filepath = $file_drupal_path;
$file->filemime = $context['cmis']->contentMimeType;
$file->filesize = filesize($file_drupal_path);
$file->status = FILE_STATUS_PERMANENT;
$file->timestamp = time();
drupal_write_record('files', $file);
// create new filefield
$node->{$field_name} = array(
array(
'fid' => $file->fid,
'title' => $context['cmis']->title,
'filename' => $file->filename,
'filepath' => $file->filepath,
'filesize' => $file->filesize,
'filemime' => $context['cmis']->contentMimeType,
'list' => 1,
),
);
}
}
}
break;
case 'text':
if ($field_value == NULL) {
$value = $content_field[0]['value'];
}
else {
$content_field[0]['value'] = $field_value;
}
break;
}
}
else {
// Regular node field value
if ($field_value == NULL) {
$value = $node->{$field_name};
}
else {
$node->{$field_name} = $field_value;
}
}
return $value;
}