Closed (fixed)
Project:
Field Collection Table
Version:
7.x-1.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
13 Feb 2012 at 06:55 UTC
Updated:
24 Apr 2015 at 10:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
dqdIf it is correct how you describe it, then this would mean that this is rather a profile2 issue. Correct me anybody if I am wrong.
Comment #2
rooby commentedWhat a coincidence, the other similar issue I remember seeing just popped up in my posts lists again.
For reference it is:
#1288522: Compatibility with profile2 (and others?)
The fix used in that issue would probably work here too.
Comment #3
lukusI've just found the same problem using profile2 and field_collection_table.
Did either of you find a fix?
Comment #4
rooby commentedI haven't had a chance to investigate.
For this project it was only a nice to have so when it didn't work I moved on and our themer worked some magic on the field collections instead (less tables = win :))
However, I'm pretty confident a solution similar to that of #1288522: Compatibility with profile2 (and others?) would work.
Although some people are now reporting that that fix didn't work, it worked fine for me.
Comment #5
rooby commentedI had a bit of an investigate for a fix in the profile2 module and it didn't seem so straight forward.
We could easily add the #entity_type and #bundle to the base of the form, and arguably it should be there on the tabs of the user edit form (because on those pages the form is actually for the single profile2 entity), however this isn't the same case on the user registration page.
Then there is also the fact that the fields of the profile2 entity are also not in the base of the form, so if we put the entity info there other modules might also expeect the fields to be there.
It gets messy from here on in.
So I abandoned that idea and went back to fixing this in the field_collection_table module.
Seeing as it is perfectly fine for what is essentially an entity form to be embedded in another form, we really should be looking deeper into the form for our widgets.
This patch makes it search through the form recursively to find fields using our widget.
This should fix support for things like nested field collections and profile2 fields and any other nested entity field situations.
Because this affects a large number of use cases, marking major.
Comment #6
rooby commentedComment #7
rooby commentedRelated in a way: #1946978: Use custom widget instead of reusing existing one and then form altering
Comment #8
jmr3460 commentedI am not sure but as I was investigating field collection table nesting another field collection, the table in the nested Field Collection Table does not display in a table. I have tried making the first Field Collection Table a table hoping it would display the nested Field Collection Table. No luck. I have seen some of these patches but I am not quite where I need to be to apply the patches.
In case anyone reads this post I am working on a project where I have created a group that could have multiple locations and each location could have multiple meetings at each location. All meetings will be associated with the single group.
I found Field collections because it allows me to allow unlimited locations for each group. Then I nested the meetings inside location field collection. Meeting Field Collections works great but I wanted to display the meeting day, time and format in a table display, so I used Field Collection Table.
Can any one tell me what I may be doing wrong?
Comment #9
rooby commentedTry the patch in #5.
It will apply from inside the field collection module directory with:
If you are not on a system where you can run the patch command see this section of the drupal handbook - https://drupal.org/patch/apply
Comment #10
jmr3460 commentedThanks for the reply. I am going to try the patch using Git.
Never done it before but have been playing with Git for a couple of days and I think I can do it. I will let you know how it goes. Thanks again for the reply.
Comment #11
jmr3460 commentedOK first attempt did not go very well. Got these errors.
error: patch failed: field_collection_table.module:192
error: field_collection_table.module: patch does not apply
I have now tried and tried to apply this patch and there are all kinds of issues.
I am sure I am doing something wrong.
If I am reading this error correctly it is saying that this patch does not apply.
Comment #12
rooby commentedAre you using Field Collection Table 7.x-1.0-beta1?
This patch is made for 7.x-1.x-dev so it might not properly apply to beta1.
If you are on beta1 I recommend upgrading to the dev version then applying the patch.
Comment #13
jmr3460 commentedI have tried again and it is complaining about some white space issue
$ git apply field_collection_table.patch
field_collection_table.patch:11: trailing whitespace.
// Search the form for field using our widget and pro
field_collection_table.patch:12: trailing whitespace.
// Sometimes entity forms are not in the base, for ex
field_collection_table.patch:13: trailing whitespace.
// nested field collections, so we check recursively.
field_collection_table.patch:14: trailing whitespace.
field_collection_table_process_form_recursive($form);
field_collection_table.patch:15: trailing whitespace.
Maybe I did not get the patch correctly. is there a zip file for this file?
Comment #14
jmr3460 commentedThanks for the help. A fellow Drupalor helped me to patch the module. It worked for me.
Thanks for the information!!!!!
Comment #15
rooby commentedGreat to hear.
Comment #16
thebruce commentedI've tested the code as well. I had a field that had nested field collections which didn't present the editing form in a tabular format much as everyone else found. After the patch the table presentation on the edit form was returned for the nested field element.
I wondered if there was some efficiency to be gained through array_walk or itterator but I think they way you have it is clear and traceable.
Nice job and thanks @rooby.
Comment #17
rooby commentedThere has been 2 reviews of working now so changing status to get maintainer attention.
@thebruce:
Might be worth checking if you have any "free time" :)
Comment #18
nancydru#5 applied cleanly to the latest
Comment #19
interdruper commentedPatch in #5 does not work in my case.
First of all, a warning is issued: Undefined variable: form_id in field_collection_table_process_form_recursive().
Anyway, after fixing the warning including $form_id as an argument to the new function,
table widget keeps not showing when it is used in a nested field collection.
I am testing it on a very simple test case, using a test entity with just 2 nested field collections:
Entity->Field Collection A (table widget works here) -> Field Collection B (table widget does NOT works here)
Versions:
Field Collection: 7.x-1.0-beta5+1-dev
Field Collection Table 7.x-1.0-beta1+2-dev
Comment #20
pebosi commentedRe-rolled #5 patch.
Applying the patch and showing two level of table's in my nested field collections works for me.
@interdruper: i use the same module versions.
Comment #21
pebosi commentedComment #22
interdruper commentedThe last patch (#20) renders correctly the nested field collections with the table widget, but...
if the nested field collection is configured to allow unlimited values,
when 'Add another item' is selected, the following error is showed:
Undefined index: #entity_type in field_collection_table_pre_render_field()
triggered in the following line:
foreach (field_info_instances($element['#entity_type'], $element['#bundle']) as $field_name => $instance)Comment #23
agrozyme commentedWe can invoke 'profile2_form_user_profile_form_alter' before process 'field_collection_table_form_alter'.
It is not a good patch, but it can use in profile2.
Comment #24
agrozyme commentedadd module_exists('profile2') before invoke 'profile2_form_user_profile_form_alter'
Comment #25
rooby commented@agrozyme:
Is the use of profile2_form_user_profile_form_alter() to make sure that the profile forms have been added before this module does its altering?
If so can you give instructions for how to see the error that this is working around? I have not seen any issues.
[EDIT] Oops sorry, is this the error referred to in #22?
Instead of calling profile2_form_user_profile_form_alter() directly (not a good idea I think) we should set the field collection table module weight to 1. I haven't looked into whether that might cause other issues but that would be the better way to make sure that profile2 form alter runs first.
Comment #26
timmarwick commentedFYI: Re: patch in comment #24 - profile2_form_user_profile_form_alter($form, $form_state); causes Field Groups to fail to render on profile2 profiles. In:
Comment #27
usdv commentedHI everyone,
I've faced with this problem with profile2. The last patch (#24) works well, but if you have a field groups it doesn't work as described in #26. So I made new patch. Please, try this, maybe my decision will help somebody or maybe someone will find a more smart way to solve this issue, find a bug etc. I used a module weight option instead of strict calling of implementation of hook_form_alter function in profile2. So it needs to run installation hooks or use query to set the module's weight if you don't want reinstall module.
Thanks everyone for posting patches!
Comment #28
rooby commentedIf ther weight is set in install it should also be set in an update hook for modules already installed.
An alternative to setting the weight in install is to use hook_module_implements_alter(), which I think is a nicer solution.
Comment #29
jgullstr commentedInstead of using hook_form_alter(), why not add the theme/prerender functions using hook_field_attach_form()? Then recursion is prevented, as fields are guaranteed to be in the root of the form array passed to the function.
I've only tested this with nested field collections.
Patch attached.
Comment #30
jgullstr commentedRe-roll for latest dev (0dfb707)
Comment #32
kevineinarsson commentedPatch #30 commited in the latest dev version.