Notice: Undefined index: undefined in plup_field_attach_presave() (line 602 of ...\sites\all\modules\plup\plup.module).

I get this error on every page refresh where a field is displayed with Plupload widget used.
It's because $bundle can sometimes be equal to "undefined" when using file_entity module.

$entityFields = $instances[$entity_type][$bundle];

I think it's in connection with this update:
look at file_entity_update_7202():

/**
 * Drupal 7.8 disallows empty string as the value for a bundle key, so update
 * empty {file_managed}.type records to 'undefined' instead.
 */
function file_entity_update_7202() {
  db_update('file_managed')
    // Using 'undefined' instead of FILE_TYPE_NONE, because update functions can
    // run for disabled modules.
    ->fields(array('type' => 'undefined'))
    ->condition('type', '')
    ->execute();
}

So I think $bundle variable should be checked:
if($bundle !== 'undefined')
OR isset() should be used:

  $entityFields = isset($instances[$entity_type][$bundle]) ? $instances[$entity_type] : NULL;

Thanks for the corrections in advance.

Comments

Sk8erPeter’s picture

Status: Active » Patch (to be ported)
StatusFileSize
new773 bytes

I attached a simple patch which can solve the problem.

deanflory’s picture

Patch failed when attempted on the latest dev version of plup (2012-Jul-04):

patching file plup.module
Hunk #1 FAILED at 599.
1 out of 1 hunk FAILED -- saving rejects to file plup.module.rej

Sk8erPeter’s picture

yes, because there are some really silly modifications in Plup's current dev release... it looks like it's full of test codes. For example: $items['pluptest'], function plup_test_form(), function plup_test_form_submit(), etc... I don't know why it was committed like this, ask the maintainer.
When I created the patch, it applied successfully. Now it seems like the module's got a brand new code, but I really don't understand why the developer didn't create another branch (like 7.x-2.x-dev or sg like this) instead of rewriting the whole code...

wreckage’s picture

Hello there.

Is there any known resolution for this problem? I'm new to Drupal and am trying to get a user photo gallery together, but Plupload is giving me the below error also:

Notice: Undefined index: file in plup_field_attach_presave() (line 585 of /mounted-storage/home2/sub002/yada-yada/MySiteName/sites/all/modules/plup/plup.module).

Any help or assistance with this will be greatly appreciated. Thank-you.

orbistertius’s picture

The patch failed tests because it missed the bundle

$entityFields = isset($instances[$entity_type][$bundle]) ? $instances[$entity_type][$bundle] : array();

This works for me.

orbistertius’s picture

Issue summary: View changes

simplifying code

patoshi’s picture

#5 confirmed working.

anyone re-roll a new patch for this?

kenorb’s picture

Issue summary: View changes
Status: Patch (to be ported) » Needs review
ericwenger’s picture

#5 worked for me also