Commit 93c5556a authored by quicksketch's avatar quicksketch

#834018: Data serialized in a field's data column is lost after...

#834018: Data serialized in a field's data column is lost after field_file_load if filefield_meta in use.
parent 6d3740d7
......@@ -38,7 +38,7 @@ function field_file_load($fid, $reset = NULL) {
}
if (!$file) {
$file = array('fid' => 0, 'filepath' => '', 'filename' => '', 'filemime' => '', 'filesize' => 0);
$file = (object) array('fid' => 0, 'filepath' => '', 'filename' => '', 'filemime' => '', 'filesize' => 0);
}
foreach (module_implements('file_load') as $module) {
......
......@@ -272,25 +272,26 @@ function filefield_field_sanitize($node, $field, &$items, $teaser, $page) {
continue;
}
}
// Load the complete file if a filepath is not available.
if (!empty($item['fid']) && empty($item['filepath'])) {
$items[$delta] = array_merge($item, field_file_load($item['fid']));
}
// Add nid so formatters can create a link to the node.
$items[$delta]['nid'] = $node->nid;
// TODO: This is only necessary for Views, which doesn't call the "load"
// $op. It might be preferable to move this to Views integration somehow.
if (!empty($items['data']) && is_string($items[$delta]['data'])) {
$item['data'] = unserialize($item['data']);
}
// Temporary fix to unserialize data serialized multiple times.
// Get the 'data' column stored by CCK into an array. This is necessary
// for Views, which doesn't call the "load" $op and to fix an issue with
// CCK double-serializing data.
// See the FileField issue http://drupal.org/node/402860.
// And the CCK issue http://drupal.org/node/407446.
while (!empty($items[$delta]['data']) && is_string($items[$delta]['data'])) {
$items[$delta]['data'] = unserialize($items[$delta]['data']);
}
// Load the complete file if a filepath is not available.
if (!empty($item['fid']) && empty($item['filepath'])) {
$file = (array) field_file_load($item['fid']);
$items[$delta]['data'] = array_merge($item['data'], $file['data']);
$items[$delta] = array_merge($item, $file);
}
// Verify the file exists on the server.
if (!empty($item['filepath']) && !file_exists($item['filepath'])) {
watchdog('filefield', 'FileField was trying to display the file %file, but it does not exist.', array('%file' => $item['filepath']), WATCHDOG_WARNING);
......
......@@ -76,7 +76,7 @@ function filefield_meta_file_load(&$file) {
function filefield_meta_file_insert(&$file) {
if (!empty($file->fid)) {
filefield_meta($file);
$record = array_merge(array('fid' => $file->fid), $file->data);
$record = array_merge($file->data, array('fid' => $file->fid));
drupal_write_record('filefield_meta', $record);
}
}
......
......@@ -204,7 +204,7 @@ function filefield_widget_value($element, $edit = FALSE) {
$item = $element['#default_value'];
}
else {
$item = array_merge($element['#default_value'], $edit);
$item = $edit;
$field = content_fields($element['#field_name'], $element['#type_name']);
// Uploads take priority over value of fid text field.
......@@ -236,6 +236,9 @@ function filefield_widget_value($element, $edit = FALSE) {
}
}
// Merge file and item data so it is available to all widgets.
if (isset($item['data']) && isset($file['data'])) {
$file['data'] = array_merge($item['data'], $file['data']);
}
$item = array_merge($item, $file);
return $item;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment