Download & Extend

FileField dissapears after upload using Multigroup

Project:FileField
Version:6.x-3.10
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:postponed
Issue tags:cck3, FileField, nested fieldgroup

Issue Summary

We are using Content Multigroup, FileField and ImageField (both 6.x-3.3)

After uploading an image, the field disappears and the field is not saved after saving the node.

See example: http://screencast.com/t/NTc4OGYxNG

After upload this is left:

<div id="edit-group-vendor-case-studies-0-field-vendor-case-logo-ahah-wrapper">
<div style="display: block;"></div>
</div>

Normal FileFields with ImageFields on the same node do work normal.

Comments

#1

Are you sure that this problem doesn't exist when a FileField is used by itself and not in a Multigroup at all? I know FileField worked with Multigroups several months ago, but I haven't checked it any time recently.

#2

Yep, 100% sure.
I could make you a video, but I am a bit short in time today ;)

#3

Status:active» postponed

I'll accept patches for this functionality, but I don't use CCK3 currently.

#4

Patch attached, it work with CCK3 (dev), and with nested_fieldgroup patch

AttachmentSize
filefield-800314-cck3-nested_multigroup.patch 1.12 KB

#5

Version:6.x-3.3» 6.x-3.9

I am also getting this error with CCK 6.x alpha-3 and filefield 3.9 and using nested groups. Works fine with the filefield in a group, but when I nest that group inside another group, upload the file, the entire widget disappears.

Below is my fix which I'm testing now. (line 620-631 of filefield.module) Hope this help.

  // Update the cached form with the new element at the right place in the form.
  if (module_exists('fieldgroup') && ($group_name = _fieldgroup_field_get_group($type_name, $field_name))) {
    if (isset($form['#multigroups']) && isset($form['#multigroups'][$group_name][$field_name])) {
      $tree = _fieldgroup_get_tree($type_name);
      $parents = array(0 => $group_name);
      while ($group_name = $tree[$group_name]['parents'][0]){
        $parents[] = $group_name;
      }
      eval('$form_element = $form["' . implode('"]["', array_reverse($parents)) . '"][$delta][$field_name];');
    }
    else {
      $tree = _fieldgroup_get_tree($type_name);
      $parents = array(0 => $group_name);
      while ($group_name = $tree[$group_name]['parents'][0]) {
        $parents[] = $group_name;
      }
      eval('$form_element = $form["' . implode('"]["', array_reverse($parents)) . '"][$field_name][$delta];');
    }
  }
  else {
    $form_element = $form[$field_name][$delta];
  }

#6

I applied patch from #4 as well as #5 and so far so good. I am attaching a re-rolled patch now. There's room for improvement as there appears to be some redundancy in the if/else.

I am now able to upload files and remove them from within nested fieldgroups without errors or blank filefield rows.

Is there a particular reason why this is postponed?

#7

Here's the updated patch.

AttachmentSize
filefield_multigroup_fix-800314-4360388.patch 1.31 KB

#8

Thank you for re-rolling the patch. Yes, there is some redundancy, but if you look carefully, the order if "[$field_name][$delta]" is one way in multigroup, and the other in multiple fields. I don't know why. One possible idea (not tested) is:

if (module_exists('fieldgroup') && ($group_name = _fieldgroup_field_get_group($type_name, $field_name))) {
  $tree = _fieldgroup_get_tree($type_name);
  $parents = array(0 => $group_name);
  while ($group_name = $tree[$group_name]['parents'][0]){
    $parents[] = $group_name;
  }
  if (isset($form['#multigroups']) && isset($form['#multigroups'][$group_name][$field_name])) {
    eval('$form_element = $form["' . implode('"]["', array_reverse($parents)) . '"][$delta][$field_name];');
  }
  else {
   eval('$form_element = $form["' . implode('"]["', array_reverse($parents)) . '"][$field_name][$delta];');
  }
}
else {
  $form_element = $form[$field_name][$delta];
}

#9

Status:postponed» needs work

Thanks for the patches guys, but this is not going to be acceptable:

      eval('$form_element = $form["' . implode('"]["', array_reverse($parents)) . '"][$field_name][$delta];');

Instead do something like this:

     $element = $form;
     foreach ($parents as $parent) {
       $element = $element[$parent];
     }
     $form_element = $element[$field_name][$delta];

#10

Ew, good call. I've never been a fan of eval() and not sure why that wasn't sticking out to me before patching. I'll try to re-roll, but if someone wants to beat me to it, please do.

#11

I implemented quicksketch suggestion to get this:

if (module_exists('fieldgroup') && ($group_name = _fieldgroup_field_get_group($type_name, $field_name))) {
  $tree = _fieldgroup_get_tree($type_name);
  $parents = array(0 => $group_name);
  while ($group_name = $tree[$group_name]['parents'][0]) {
    $parents[] = $group_name;
  }
  $parents = array_reverse($parents);

  $element = $form;
  foreach ($parents as $parent) {
    $element = $element[$parent];
  }

  if (isset($form['#multigroups']) && isset($form['#multigroups'][$group_name][$field_name])) {
    $form_element = $element[$delta][$field_name];
  }
  else {
    $form_element = $element[$field_name][$delta];
  }
}
else {
  $form_element = $form[$field_name][$delta];
}

#12

Didn't work for me, using CCK 6.x alpha-3 and filefield 3.10. I removed the check for #multigroups and everything works again using this:

  // Update the cached form with the new element at the right place in the form.
if (module_exists('fieldgroup') && ($group_name = _fieldgroup_field_get_group($type_name, $field_name))) {
$tree = _fieldgroup_get_tree($type_name);
$parents = array(0 => $group_name);
while ($group_name = $tree[$group_name]['parents'][0]) {
$parents[] = $group_name;
}
$parents = array_reverse($parents);

$element = $form;
foreach ($parents as $parent) {
$element = $element[$parent];
}

$form_element = $element[$delta][$field_name];
}
else {
$form_element = $form[$field_name][$delta];
}

#13

#11 works; #12 does not.

here is actual patch file.

AttachmentSize
800314.patch 1.24 KB

#14

I swear every time we get new Multigroup code it gets more confusing. :P

#15

#13 isn't working for me, but #12 is.

#16

#12 works for me too, #11 and #13 doesn't

Be nice to get this rolled into the module?

#17

Any solution so far? Subscribing

#18

Status:needs work» postponed

Be nice to get this rolled into the module?

As I don't use Multigroup or CCK 3, any users of this patch need to:

A) Come to a consensus about what works (and what doesn't).

B) Provide a patch that adds the necessary code (hopefully minimal) and doesn't break CCK 2. And get multiple reviews confirming it works.

#19

Version:6.x-3.9» 6.x-3.10

#12 worked well for me with

  • filefield 6.x-3.10
  • 6.x-3.x-dev (up to date)

#20

#11 worked for me with dev and cck3 alpha

#21

#11 is working for me in some cases, #12 in other cases. But both just are partial solutions, I need them combined! I can't seem to figure out a working combination of both though...

#22

Somethin I observed while having this problem:

The filefield widget only disappears when I put the fields of a multigroup into columns via the "Multiple columns" option when editing the group. May this be part of the problem?

#23

I have them as a fieldset, so that's no part of the problem.

#24

Just sharing my experience.
The setups are tested with just the default modules, no patches:
filefield 6.x-3.10
cck 6.x-3.x-dev (up to date)

Setup 1: works
> group A
- - Multifile field

Setup 2: works
> Multigroup B
- - File field

Setup 3: fails (field disappears on upload)
> group C
- > Multigroup B
- - - File field

For setup 3 using the patch from #12 will make it work, but will cause setup 1 to fail (field disappears on upload)

#25

#13 Worked for me, thx :)

#26

Any new thoughts?

#27

In my case, I've started using Multigroup before the FileField fix. Presumably some administration was done in the field list (& group list) in the interim. I'm not exactly sure how this led to the result, but when I checked {content_group_fields}, I found that the file fields had two entries each, one to the actual Multigroup, one to an empty group (possibly due to how the group name was emptied while I was moving it around in the interim).

So, I got rid of the invalid entries, and it worked like a dream.

EDIT:
Would this be a candidate for an update hook?

#28

For me #12 worked. #11 did not.

#29

I confirm #24s Behaviour. #12 will make Setup 3 work, but cause 1 to fail.

#30

This is based on #12, but does not break #24's Setup 1.

AttachmentSize
filefield-nested_multigroup_fix2-800314.patch 1.93 KB

#31

@nils_r: I tried applying your patch in #30 because I need it to work for all those cases in #24 and it did not work. I applied it to filefield 3.10. I had to manually apply it because the pre-state didn't work. Which version of filefield are you using?

I am using CCK 3.0-alpha with a standard Drupal 6 install (base install, no mods).

Anyway, I couldn't wait for a patch to come along. So I took your patch (@nils_r #30) and modified it. Your patch was really really close. I used the first part of it. I dumped the multigroups crap. The code now detects the parent structure THEN it iterates down that structure to the field. Once it finds the field it then looks for the delta and if it fails to find it then it resorts to the field details found.

I tried this fix of mine in my base D6 install with CCK 3.0 alpha and filefield 3.10. It is just one area that needs to be fixed. The rest works great.

I have attached the SVN diff file. It is not a git patch file yet. I will send that in my next post.

AttachmentSize
filefield-3.10-multigroup_fix.diff 1.63 KB

#32

Ok here is the patch file as well. This is applied to the latest checked out copy (which seems to be filefield 3.10 verbatim, despite the long release timeframe). This has been tested with D6 6.22 AND Pressflow 6.22 with CCK 6.x-3.0-alpha3.

Let me know if you guys have any problems with it. Thanks!

AttachmentSize
filefield_cck3_multigroup_fix-800314-32.patch 1.62 KB

#33

I had the same problem. It turns out there were duplicate entries in db table `content_group_fields` with empty group_name. Removing these records fixed the problem. I didn't have to modify any code. There surely is a bug somewhere in either filefield or fieldgroup module, but I didn't have time to find and fix it.

#34

I just discovered the same thing as in #33. Looks like there's an issue with moving things about in the "Manage Fields" interface that leaves bits where they shouldn't be. In my case, the field appeared twice in the table, once with the group name and once without (no group name). Removing the row without the group name solved my problem.