Hi. I'm working with 6.x, in the _plupload_imagefield_import_create_node() function. There is a block of code that looks like this:

  // Make it easy for other modules to add data to imported nodes using
  // hook_form_alter (see http://drupal.org/node/714550 for details).
  foreach (array_keys($options) as $key) {
    if (!isset($node->$key)) {
      $node->$key = $options[$key];
    }
  }

  // Add any additional cck fields set during import.
  $type = content_types($field['type_name']);
  if (!empty($type['fields'])) {
    foreach ($type['fields'] as $name => $field) {
      if ($field['type'] != 'filefield') {
        $node->$name = $form_state_values[$name];
      }
    }
  }

The first block allows us to pass an $options array into the function to define additional CCK fields to add. That code is fine. Let's say we passed in an $options array for field_myfield with a few values.

The second block of code effectively overwrites any custom CCK fields. It grabs all defined fields for the node type (which will inclue field_myfield), and then for any fields that are not a filefield it populates the value with whatever is in $form_state_values. Since our custom field does not have a value in $form_state_values, this blows away the value from the $options array that was just set in the first code block.

CommentFileSizeAuthor
#1 1484750-1.patch1.21 KBrjbrown99
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rjbrown99’s picture

Status: Active » Needs review
FileSize
1.21 KB

Patch attached. I just swapped the order of those code blocks.

muri’s picture

Status: Needs review » Active
muri’s picture

This patch is not working in the right way. Let's say we also attached some non-filefields to the node type which we assigned the filefield to it via plupload admin settings. If these non-filefields have defualt values they will be lost during node form submission. So these fields need to be attached to form state values

// Create some defaults that imagefield expects.
      $form_state_values = array(
        'title' => $file_name,
        'body' => '',
        'field_photo' => array(0 => array(
            'fid' => 0,
            'list' => '1',
            'filepath' => '',
            'filename' => '',
            'filemime' => '',
            'filesize' => 0,
            'filefield_upload' => 'Upload',
            'filefield_remove' => 'Remove',
            'upload' => 0,
          ),
        'node_status' => NULL,
        )
      );

and such a code below can be added to fix the issue.

// Get the other node fields which are not filefield
      $type = content_types($field['type_name']);
      if (!empty($type['fields'])) {
        foreach ($type['fields'] as $name => $field) {
          if ($field['type'] != 'filefield') {
            $form_state_values[$name] = $field;
          }
        }
      }

A patch will be released to fix this issue.