#prefix and #suffix aren't used in content multigroups
| Project: | Popups: Add and Reference |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
1. I use the popups_reference module which add in the #prefix and #suffix a link to add a new Node.
2. What is expected: a link to create a new node under the nodereference field.
3. What I get is no link at all.
4. The popups_reference works well with anywhere else except multigroups. That's why I don't think the problem is inside the popups_reference module. When I trace and output $form, I can see that the prefixes and suffixes are set. But they aren't used.
5. I'd like to fix it but I really don't know how. I struggled to find where exactly those #prefix and #suffix values are used. I guess the fix should be really simple but I really have no idea how it works. If someone can give me a hint where to look to add the prefixes and suffixes I'll submit a patch as soon as I can.
I also saw that the prefix and suffix aren't used for any other field. I saw that my file field don't show them as well but it isn't critical for other case. I really need the popups_reference module to work with multigroup.
Thank you, Loïc

#1
229 $prefix = isset($form[$field_name]['#prefix']) ? $form[$field_name]['#prefix'] : $form[$group_name][$field_name]['#prefix'];
230 $suffix = isset($form[$field_name]['#suffix']) ? $form[$field_name]['#suffix'] : $form[$group_name][$field_name]['#suffix'];
231
232 $form[$group_name][$delta][$field_name] = $field_form[$field_name];
233 $form[$group_name][$delta][$field_name]['#prefix'] = $prefix;
234 $form[$group_name][$delta][$field_name]['#suffix'] = $suffix;
Here is a small fix. But there is still a problem with it.
When we click to add a new multigroup. It will use the form from the cache. In other words...the values prefix aren't there...the popups_reference alter can't be called anymore so in content_multigroup_add_more_js...We should regenerate a new multigroup instead of just using the values from the cache.
Unless I got something wrong there. But I know that the place I get my #prefix and #suffix aren't set with the javascript call
#2
Sorry, but I think this is a issue with the way Popups Add and Reference alters the node reference fields. It does so at form_alter() time, and it probably needs to do it using an after_build callback, or maybe use a different method to scan the form elements.
Probably related issue: #388406: multiple values nodereference field
#3
I don't know, I got it to work without modifying the popups behaviour.
I noticed that multigroup never use the #prefix or #suffix already set on some fields. That's what my fix above corrected.
I'll post a "valid" patch later. I forgot to mention which file I modified...
My point is still that same if popups change its behaviour for after_build... multigroup will still not use #prefix or #suffix for any other "thing" field or anything that can be rendered by multigroup.
#4
Nope. I think you're confused. The multigroup will use a prefix if it is defined properly. For example, edit nodereference.module and apply this mini patch:
<?php$element[$field_key] = array(
'#type' => 'text_textfield',
+ '#prefix' => '<div style="border:1px solid red">',
+ '#suffix' => '</div>',
'#default_value' => isset($element['#value']) ? $element['#value'] : '',
?>
Now, no matter where you place the field, you'll see how all your nodereference fields are enclosed on a red box, even on multigroups.
So, where's the problem? What happens is that popups inserts prefix and suffix to a version of the noderef which is discarded by the multigroup, because the multigroup module needs to build single valued versions of the fields. So the popups module needs to be wise enough to alter the fields in a way that affects the version used on multigroups. How? Use an after_build callback that's executed after the multigroup processing, which is invoked by fieldgroup using a hook, and fieldgroup module weight is not 0, so that matters. Also, popups module should traverse the form structure recursively because the fields may be located several levels deep, and this will be worst when the nested fieldgroup patch gets in.
#5
Possibly a duplicate of this?
#397614: Append to #prefix and #suffix instead of overwrite