The table widget doesn't work with profile2 profiles.

This is because the #entity_type & #bundle aren't in the base of the form they are actually in $form['profile_PROFILENAME'].

I have come across other modules having this same issue with profile2 but I can't remember right now where sorry, I'm in a bit of a rush at the moment.

Comments

dqd’s picture

Project: Field Collection Table » Profile 2
Priority: Major » Normal

I have come across other modules having this same issue with profile2

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

rooby’s picture

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

lukus’s picture

I've just found the same problem using profile2 and field_collection_table.

Did either of you find a fix?

rooby’s picture

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

rooby’s picture

Project: Profile 2 » Field Collection Table
Priority: Normal » Major
Status: Active » Needs review
StatusFileSize
new2.44 KB

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

rooby’s picture

Title: Widget doesn't work with field collections on profile2 profiles » Widget doesn't work with nested entity forms, like profile2 and nested field_collection
rooby’s picture

jmr3460’s picture

I 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?

rooby’s picture

Try the patch in #5.

It will apply from inside the field collection module directory with:

patch -p1 < field_collection_table-recurse_form-1438266-5.patch

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

jmr3460’s picture

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

jmr3460’s picture

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

rooby’s picture

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

jmr3460’s picture

I 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?

jmr3460’s picture

Thanks for the help. A fellow Drupalor helped me to patch the module. It worked for me.
Thanks for the information!!!!!

rooby’s picture

Great to hear.

thebruce’s picture

I'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.

rooby’s picture

Status: Needs review » Reviewed & tested by the community

There 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" :)

nancydru’s picture

#5 applied cleanly to the latest

interdruper’s picture

Status: Reviewed & tested by the community » Needs work

Patch 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

pebosi’s picture

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

pebosi’s picture

Status: Needs work » Needs review
interdruper’s picture

Status: Needs review » Needs work

The 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)

agrozyme’s picture

Issue summary: View changes
StatusFileSize
new3.04 KB

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

agrozyme’s picture

StatusFileSize
new3.08 KB

add module_exists('profile2') before invoke 'profile2_form_user_profile_form_alter'

rooby’s picture

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

timmarwick’s picture

FYI: 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:

function field_collection_table_form_alter_invoke(&$form, &$form_state) {
	switch ($form['#form_id']) {
		case 'user_profile_form':
			if (module_exists('profile2')) {
	    	           profile2_form_user_profile_form_alter($form, $form_state);
			}
			break;

		default:
			break;
	}
}
usdv’s picture

HI 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!

rooby’s picture

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

jgullstr’s picture

Status: Needs work » Needs review
StatusFileSize
new3.22 KB

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

jgullstr’s picture

StatusFileSize
new3.05 KB

Re-roll for latest dev (0dfb707)

kevineinarsson’s picture

Status: Needs review » Fixed

Patch #30 commited in the latest dev version.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.