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

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.

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

Status:Active» Postponed

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

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

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];
  }

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?

Here's the updated patch.

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];
}

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];

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.

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];
}

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];
}

StatusFileSize
new1.24 KB

#11 works; #12 does not.

here is actual patch file.

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

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

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

Be nice to get this rolled into the module?

Any solution so far? Subscribing

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.

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)

#11 worked for me with dev and cck3 alpha

#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...

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?

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

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)

#13 Worked for me, thx :)

Any new thoughts?

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?

For me #12 worked. #11 did not.

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

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

StatusFileSize
new1.63 KB

@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.

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!

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.

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.

Title:FileField dissapears after upload using MultigroupFileField disappears after upload using Multigroup

I tried the patch in #32 and it didn't seem to do anything. My version of Drupal is 6.19. I have a bit of a pieced together CCK module due to patches from http://drupal.org/node/1167004, but the base is 6.x-3.0-alpha3. Any suggestions?

EDIT: I updated to Drupal 6.26. I installed alpha CCK and the latest FileField module plus the patch from #32. It didn't fix the issue. I also tried with the 6.x-3.x-dev version of CCK.

My boss and I got the most recent patch to work on our end. What was missing was the initial if/else statement that was replaced/lost in the patch.

Provided is our working code. I don't know how to create a patch.

I feel comfortable in saying this fixes the issue on my end, but not the whole issue as we haven't tested it much.

<?php
   
//the original if/else
    /*if (isset($form['#multigroups']) && isset($form['#multigroups'][$group_name][$field_name])) {
      $form_element = $form[$group_name][$delta][$field_name];
    }
    else {
      $form_element = $form[$group_name][$field_name][$delta];
    }*/
    //Get the fieldgroup tree information for this field
   
$tree = _fieldgroup_get_tree($type_name);
   
$parents = array(0 => $group_name);
   
//Find the parent structure
   
$tmp_group_name = $group_name; //don't overwrite $group_name
   
while ($tmp_group_name = $tree[$tmp_group_name]['parents'][0]) {
     
$parents[] = $tmp_group_name;
    }
   
//Put in the correct order
   
$parents = array_reverse($parents);
   
$tmp_element = $form;
   
//Now we need to find the field within the structure. So iterate down to its parents level.
   
foreach ($parents as $idx) {
      if (isset(
$tmp_element[$idx]) && is_array($tmp_element[$idx])) {
       
$tmp_element = $tmp_element[$idx];
      }
    }
   
//the field is found now determine if this is in a multigroup
    //using the original if/else
   
if (isset($form['#multigroups']) && isset($form['#multigroups'][$group_name][$field_name])) {
       
//multigroup structure is $tmp_element[$delta][$field_name]
       
$form_element = $tmp_element[$delta][$field_name];
    }
    else {
       
//non-multigroup structure is $tmp_element[$field_name] or $tmp_element[$field_name][$delta]
       
$field = $tmp_element[$field_name];
        if (isset(
$field[$delta])) {
         
$form_element = $field[$delta];
        }
        else {
         
$form_element = $field;
        }
    }
?>

@jstnhffmn: Creating a patch is really easy. I hope your using a Unix/Linux based system (like Mac OSX and any Linux distro), otherwise using git is a huge pain in the ass.

Once you get git installed (instructions are all over the internet) you need to check out a copy of the filefield branch that you modified. Go here for instructions on this: http://drupal.org/project/filefield/git-instructions

After using git clone on the copy of the module you need to manually apply your changes to the files. Then follow the instructions in the above URL for creating the *.patch file. After creating that file put it up on this ticket. If you are confused by the naming convention here is an example that assumes your comment comes right after mine: fix_filefield_upload-800314-38.patch

Status:Postponed» Needs review
StatusFileSize
new1.85 KB

Here is a patch file for the fix in #36, I can confirm it solves the problem for me too. Thanks jstnhffmn!

#38 worked for me