Commit e1b223b1 authored by Dries's avatar Dries
Browse files

- Patch #984456 by Dave Reid, bfroehle: cleanup file_field_widget_uri() and its token replacement.

parent f2730416
...@@ -567,14 +567,17 @@ function file_field_widget_upload_validators($field, $instance) { ...@@ -567,14 +567,17 @@ function file_field_widget_upload_validators($field, $instance) {
* A field array. * A field array.
* @param $instance * @param $instance
* A field instance array. * A field instance array.
* @param $data
* An array of token objects to pass to token_replace().
* @return * @return
* A file directory URI with tokens replaced. * A file directory URI with tokens replaced.
*
* @see token_replace()
*/ */
function file_field_widget_uri($field, $instance, $account = NULL) { function file_field_widget_uri($field, $instance, $data = array()) {
$destination = trim($instance['settings']['file_directory'], '/'); $destination = trim($instance['settings']['file_directory'], '/');
// Replace tokens. // Replace tokens.
$data = array('user' => isset($account) ? $account : $GLOBALS['user']);
$destination = token_replace($destination, $data); $destination = token_replace($destination, $data);
return $field['settings']['uri_scheme'] . '://' . $destination; return $field['settings']['uri_scheme'] . '://' . $destination;
......
...@@ -932,7 +932,7 @@ class FileFieldPathTestCase extends FileFieldTestCase { ...@@ -932,7 +932,7 @@ class FileFieldPathTestCase extends FileFieldTestCase {
// Check the path when used with tokens. // Check the path when used with tokens.
// Change the path to contain multiple token directories. // Change the path to contain multiple token directories.
$field = $this->updateFileField($field_name, $type_name, array('file_directory' => '[user:uid]/[user:name]')); $field = $this->updateFileField($field_name, $type_name, array('file_directory' => '[current-user:uid]/[current-user:name]'));
// Upload a new file into the token subdirectories. // Upload a new file into the token subdirectories.
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
...@@ -940,6 +940,8 @@ class FileFieldPathTestCase extends FileFieldTestCase { ...@@ -940,6 +940,8 @@ class FileFieldPathTestCase extends FileFieldTestCase {
// Check that the file was uploaded into the subdirectory. // Check that the file was uploaded into the subdirectory.
$node = node_load($nid, NULL, TRUE); $node = node_load($nid, NULL, TRUE);
$node_file = (object) $node->{$field_name}[LANGUAGE_NONE][0]; $node_file = (object) $node->{$field_name}[LANGUAGE_NONE][0];
// Do token replacement using the same user which uploaded the file, not
// the user running the test case.
$data = array('user' => $this->admin_user); $data = array('user' => $this->admin_user);
$subdirectory = token_replace('[user:uid]/[user:name]', $data); $subdirectory = token_replace('[user:uid]/[user:name]', $data);
$this->assertPathMatch('public://' . $subdirectory . '/' . $test_file->filename, $node_file->uri, t('The file %file was uploaded to the correct path with token replacements.', array('%file' => $node_file->uri))); $this->assertPathMatch('public://' . $subdirectory . '/' . $test_file->filename, $node_file->uri, t('The file %file was uploaded to the correct path with token replacements.', array('%file' => $node_file->uri)));
......
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