Most recent version of drupal core dev results in an AJAX http error when using file fields mapping. The exact error in dblog is:

Recoverable fatal error: Argument 2 passed to token_replace() must be an array, object given, called in /var/aegir/drupal7/modules/file/file.field.inc on line 581 and defined in token_replace() (line 76 of /var/aegir/drupal7/includes/token.inc).

The quick fix to get functional feeds back is to swap the new file_field_widget_uri function in the above mentioned file.field.inc back to the previous as below. Not quite sure where the error is (as I am using filefield_sources also), but this will get feeds back online for now.

function file_field_widget_uri($field, $instance, $account = NULL) {
  $destination = trim($instance['settings']['file_directory'], '/');

  // Replace tokens.
  $data = array('user' => isset($account) ? $account : $GLOBALS['user']);
  $destination = token_replace($destination, $data);

  return $field['settings']['uri_scheme'] . '://' . $destination;
}

Comments

Anonymous’s picture

I experienced this same thing, as exposed through the Feeds module (http://drupal.org/node/1169986). This fix took care of the issue for me.

bcostlow’s picture

StatusFileSize
new1.2 KB

Feeds calls file_field_widget_uri() in mappers/file.inc (Line 69) which is causing this AJAX error.

$account = !empty($entity->uid) ? user_load($entity->uid) : NULL;
$destination = file_field_widget_uri($info, $instance_info, $account);

Replace with:

  $data = array('user' => !empty($entity->uid) ? user_load($entity->uid) : $GLOBALS['user']);
  $destination = file_field_widget_uri($info, $instance_info, $data);

which preserves the functionality of the old file_field_widget_uri() and prevents the AJAX error.

glottus’s picture

subscribing

wojtha’s picture

Status: Active » Needs review
StatusFileSize
new0 bytes

I don't think that we should assign the authorship of the entity to the current user if no entity UID exist. Better fallback will be assign the entity to anonymous user. We probably also want to check if the account really exists or we get FALSE from the user_load() which will cause same error in token_replace() as the NULL.

wojtha’s picture

StatusFileSize
new960 bytes

Sorry, empty patch.

wojtha’s picture

Title: Most recent version of drupal core causes AJAX Http error » Error in file mapper - 2nd argument passed to token_replace() must be an array
StatusFileSize
new0 bytes

Sorry for the second empty patch, I unwittingly post the previous form from the browser history... omg.

I just wanted to change the title, patch in #5 still applies.

thill_’s picture

Status: Needs review » Closed (duplicate)