Commit 9713fab0 authored by catch's avatar catch

Issue #1446464 by cfennell, Berdir, aaron, tim.plunkett: Get rid of...

Issue #1446464 by cfennell, Berdir, aaron, tim.plunkett: Get rid of file_field_load() - shouldn't load all file object data with field load - only file ID.
parent 46065f0b
......@@ -180,18 +180,23 @@ function _file_generic_settings_file_directory_validate($element, &$form_state)
}
/**
* Implements hook_field_load().
* Implements hook_field_prepare_view().
*/
function file_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) {
function file_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) {
// Remove files specified to not be displayed.
$fids = array();
foreach ($entities as $id => $entity) {
// Load the files from the files table.
foreach ($items[$id] as $delta => $item) {
if (!empty($item['fid'])) {
if (!file_field_displayed($item, $field)) {
unset($items[$id][$delta]);
}
elseif (!empty($item['fid'])) {
// Load the files from the files table.
$fids[] = $item['fid'];
}
}
// Ensure consecutive deltas.
$items[$id] = array_values($items[$id]);
}
$files = file_load_multiple($fids);
......@@ -208,22 +213,6 @@ function file_field_load($entity_type, $entities, $field, $instances, $langcode,
}
}
/**
* Implements hook_field_prepare_view().
*/
function file_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) {
// Remove files specified to not be displayed.
foreach ($entities as $id => $entity) {
foreach ($items[$id] as $delta => $item) {
if (!file_field_displayed($item, $field)) {
unset($items[$id][$delta]);
}
}
// Ensure consecutive deltas.
$items[$id] = array_values($items[$id]);
}
}
/**
* Implements hook_field_insert().
*/
......
......@@ -174,7 +174,7 @@ function file_file_download($uri, $field_type = 'file') {
// Find the field item with the matching URI.
foreach ($field_items as $field_item) {
if ($field_item['uri'] == $uri) {
if (file_load($field_item['fid'])->uri == $uri) {
$field = field_info_field($field_name);
break;
}
......
......@@ -58,7 +58,7 @@ function testNodeDisplay() {
// Check that the default formatter is displaying with the file name.
$node = node_load($nid, NULL, TRUE);
$node_file = (object) $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0];
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
$default_output = theme('file_link', array('file' => $node_file));
$this->assertRaw($default_output, t('Default formatter displaying correctly on full node view.'));
......
......@@ -33,7 +33,7 @@ function testUploadPath() {
// Check that the file was uploaded to the file root.
$node = node_load($nid, NULL, TRUE);
$node_file = (object) $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0];
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
$this->assertPathMatch('public://' . $test_file->filename, $node_file->uri, t('The file %file was uploaded to the correct path.', array('%file' => $node_file->uri)));
// Change the path to contain multiple subdirectories.
......@@ -44,7 +44,7 @@ function testUploadPath() {
// Check that the file was uploaded into the subdirectory.
$node = node_load($nid, NULL, TRUE);
$node_file = (object) $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0];
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
$this->assertPathMatch('public://foo/bar/baz/' . $test_file->filename, $node_file->uri, t('The file %file was uploaded to the correct path.', array('%file' => $node_file->uri)));
// Check the path when used with tokens.
......@@ -56,7 +56,7 @@ function testUploadPath() {
// Check that the file was uploaded into the subdirectory.
$node = node_load($nid, NULL, TRUE);
$node_file = (object) $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0];
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
// Do token replacement using the same user which uploaded the file, not
// the user running the test case.
$data = array('user' => $this->admin_user);
......
......@@ -47,7 +47,7 @@ function testRevisions() {
// Check that the file exists on disk and in the database.
$node = node_load($nid, NULL, TRUE);
$node_file_r1 = (object) $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0];
$node_file_r1 = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
$node_vid_r1 = $node->vid;
$this->assertFileExists($node_file_r1, t('New file saved to disk on node creation.'));
$this->assertFileEntryExists($node_file_r1, t('File entry exists in database on node creation.'));
......@@ -56,7 +56,7 @@ function testRevisions() {
// Upload another file to the same node in a new revision.
$this->replaceNodeFile($test_file, $field_name, $nid);
$node = node_load($nid, NULL, TRUE);
$node_file_r2 = (object) $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0];
$node_file_r2 = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
$node_vid_r2 = $node->vid;
$this->assertFileExists($node_file_r2, t('Replacement file exists on disk after creating new revision.'));
$this->assertFileEntryExists($node_file_r2, t('Replacement file entry exists in database after creating new revision.'));
......@@ -64,7 +64,7 @@ function testRevisions() {
// Check that the original file is still in place on the first revision.
$node = node_load($nid, $node_vid_r1, TRUE);
$this->assertEqual($node_file_r1, (object) $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0], t('Original file still in place after replacing file in new revision.'));
$this->assertEqual($node_file_r1, file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']), t('Original file still in place after replacing file in new revision.'));
$this->assertFileExists($node_file_r1, t('Original file still in place after replacing file in new revision.'));
$this->assertFileEntryExists($node_file_r1, t('Original file entry still in place after replacing file in new revision'));
$this->assertFileIsPermanent($node_file_r1, t('Original file is still permanent.'));
......@@ -73,7 +73,7 @@ function testRevisions() {
// Check that the file is still the same as the previous revision.
$this->drupalPost('node/' . $nid . '/edit', array('revision' => '1'), t('Save'));
$node = node_load($nid, NULL, TRUE);
$node_file_r3 = (object) $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0];
$node_file_r3 = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
$node_vid_r3 = $node->vid;
$this->assertEqual($node_file_r2, $node_file_r3, t('Previous revision file still in place after creating a new revision without a new file.'));
$this->assertFileIsPermanent($node_file_r3, t('New revision file is permanent.'));
......@@ -81,7 +81,7 @@ function testRevisions() {
// Revert to the first revision and check that the original file is active.
$this->drupalPost('node/' . $nid . '/revisions/' . $node_vid_r1 . '/revert', array(), t('Revert'));
$node = node_load($nid, NULL, TRUE);
$node_file_r4 = (object) $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0];
$node_file_r4 = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
$node_vid_r4 = $node->vid;
$this->assertEqual($node_file_r1, $node_file_r4, t('Original revision file still in place after reverting to the original revision.'));
$this->assertFileIsPermanent($node_file_r4, t('Original revision file still permanent after reverting to the original revision.'));
......@@ -95,7 +95,8 @@ function testRevisions() {
// Attach the second file to a user.
$user = $this->drupalCreateUser();
$user->{$field_name}[LANGUAGE_NOT_SPECIFIED][0] = (array) $node_file_r3;
$user->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'] = $node_file_r3->fid;
$user->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['display'] = 1;
$user->save();
$this->drupalGet('user/' . $user->uid . '/edit');
......
......@@ -46,7 +46,7 @@ function testRequired() {
$node = node_load($nid, NULL, TRUE);
$node_file = (object) $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0];
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
$this->assertFileExists($node_file, t('File exists after uploading to the required field.'));
$this->assertFileEntryExists($node_file, t('File entry exists after uploading to the required field.'));
......@@ -62,7 +62,7 @@ function testRequired() {
// Create a new node with the uploaded file into the multivalue field.
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
$node = node_load($nid, NULL, TRUE);
$node_file = (object) $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0];
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
$this->assertFileExists($node_file, t('File exists after uploading to the required multiple value field.'));
$this->assertFileEntryExists($node_file, t('File entry exists after uploading to the required multipel value field.'));
......@@ -98,7 +98,7 @@ function testFileMaxSize() {
// Create a new node with the small file, which should pass.
$nid = $this->uploadNodeFile($small_file, $field_name, $type_name);
$node = node_load($nid, NULL, TRUE);
$node_file = (object) $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0];
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
$this->assertFileExists($node_file, t('File exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->filesize), '%maxsize' => $max_filesize)));
$this->assertFileEntryExists($node_file, t('File entry exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->filesize), '%maxsize' => $max_filesize)));
......@@ -114,7 +114,7 @@ function testFileMaxSize() {
// Upload the big file successfully.
$nid = $this->uploadNodeFile($large_file, $field_name, $type_name);
$node = node_load($nid, NULL, TRUE);
$node_file = (object) $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0];
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
$this->assertFileExists($node_file, t('File exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->filesize))));
$this->assertFileEntryExists($node_file, t('File entry exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->filesize))));
......@@ -141,7 +141,7 @@ function testFileExtension() {
// Check that the file can be uploaded with no extension checking.
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
$node = node_load($nid, NULL, TRUE);
$node_file = (object) $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0];
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
$this->assertFileExists($node_file, t('File exists after uploading a file with no extension checking.'));
$this->assertFileEntryExists($node_file, t('File entry exists after uploading a file with no extension checking.'));
......@@ -159,7 +159,7 @@ function testFileExtension() {
// Check that the file can be uploaded with extension checking.
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
$node = node_load($nid, NULL, TRUE);
$node_file = (object) $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0];
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
$this->assertFileExists($node_file, t('File exists after uploading a file with extension checking.'));
$this->assertFileEntryExists($node_file, t('File entry exists after uploading a file with extension checking.'));
......
......@@ -42,7 +42,7 @@ function testSingleValuedWidget() {
// does not yet support file uploads.
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
$node = node_load($nid, NULL, TRUE);
$node_file = (object) $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0];
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
$this->assertFileExists($node_file, t('New file saved to disk on node creation.'));
// Ensure the file can be downloaded.
......@@ -218,7 +218,7 @@ function testPrivateFileSetting() {
$this->drupalPost("admin/structure/types/manage/$type_name/fields/$field_name", $edit, t('Save settings'));
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
$node = node_load($nid, NULL, TRUE);
$node_file = (object) $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0];
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
$this->assertFileExists($node_file, t('New file saved to disk on node creation.'));
// Ensure the private file is available to the user who uploaded it.
......@@ -284,7 +284,7 @@ function testPrivateFileComment() {
$this->drupalLogin($user);
$comment = comment_load($cid);
$comment_file = (object) $comment->{'field_' . $name}[LANGUAGE_NOT_SPECIFIED][0];
$comment_file = file_load($comment->{'field_' . $name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
$this->assertFileExists($comment_file, t('New file saved to disk on node creation.'));
// Test authenticated file download.
$url = file_create_url($comment_file->uri);
......
......@@ -40,7 +40,7 @@ function testPrivateFile() {
$test_file = $this->getTestFile('text');
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name, TRUE, array('private' => TRUE));
$node = node_load($nid, NULL, TRUE);
$node_file = (object) $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0];
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
// Ensure the file can be downloaded.
$this->drupalGet(file_create_url($node_file->uri));
$this->assertResponse(200, t('Confirmed that the generated URL is correct by downloading the shipped file.'));
......
......@@ -179,17 +179,12 @@ function _image_field_resolution_validate($element, &$form_state) {
}
}
/**
* Implements hook_field_load().
*/
function image_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) {
file_field_load($entity_type, $entities, $field, $instances, $langcode, $items, $age);
}
/**
* Implements hook_field_prepare_view().
*/
function image_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) {
// Load the images.
file_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, $items);
// If there are no files specified at all, use the default.
foreach ($entities as $id => $entity) {
if (empty($items[$id])) {
......
......@@ -235,7 +235,7 @@ function testStyleReplacement() {
// Test that image is displayed using newly created style.
$this->drupalGet('node/' . $nid);
$this->assertRaw(image_style_url($style_name, $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['uri']), t('Image displayed using style @style.', array('@style' => $style_name)));
$this->assertRaw(image_style_url($style_name, file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri), t('Image displayed using style @style.', array('@style' => $style_name)));
// Rename the style and make sure the image field is updated.
$new_style_name = strtolower($this->randomName(10));
......@@ -245,7 +245,7 @@ function testStyleReplacement() {
$this->drupalPost('admin/config/media/image-styles/edit/' . $style_name, $edit, t('Update style'));
$this->assertText(t('Changes to the style have been saved.'), t('Style %name was renamed to %new_name.', array('%name' => $style_name, '%new_name' => $new_style_name)));
$this->drupalGet('node/' . $nid);
$this->assertRaw(image_style_url($new_style_name, $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['uri']), t('Image displayed using style replacement style.'));
$this->assertRaw(image_style_url($new_style_name, file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri), t('Image displayed using style replacement style.'));
// Delete the style and choose a replacement style.
$edit = array(
......@@ -256,6 +256,6 @@ function testStyleReplacement() {
$this->assertRaw($message, $message);
$this->drupalGet('node/' . $nid);
$this->assertRaw(image_style_url('thumbnail', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['uri']), t('Image displayed using style replacement style.'));
$this->assertRaw(image_style_url('thumbnail', file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri), t('Image displayed using style replacement style.'));
}
}
......@@ -51,7 +51,7 @@ function _testImageFieldFormatters($scheme) {
$node = node_load($nid, NULL, TRUE);
// Test that the default formatter is being used.
$image_uri = $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['uri'];
$image_uri = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri;
$image_info = array(
'uri' => $image_uri,
'width' => 40,
......@@ -154,7 +154,7 @@ function testImageFieldSettings() {
// style.
$node = node_load($nid, NULL, TRUE);
$image_info = array(
'uri' => image_style_url('medium', $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['uri']),
'uri' => image_style_url('medium', file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri),
'width' => 220,
'height' => 110,
);
......@@ -163,7 +163,7 @@ function testImageFieldSettings() {
// Add alt/title fields to the image and verify that they are displayed.
$image_info = array(
'uri' => $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['uri'],
'uri' => file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri,
'alt' => $this->randomName(),
'title' => $this->randomName(),
'width' => 40,
......@@ -230,7 +230,7 @@ function testImageFieldDefaultImage() {
$nid = $this->uploadNodeImage($images[1], $field_name, 'article');
$node = node_load($nid, NULL, TRUE);
$image_info = array(
'uri' => $node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['uri'],
'uri' => file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri,
'width' => 40,
'height' => 20,
);
......
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