Comments

joachim’s picture

Status: Active » Needs work
StatusFileSize
new7.63 KB

WIP patch; nearly there but there seems to be something wrong with the AJAX not getting loaded back in. No time to dig further right now, but posting this for later (or in case someone else feels like picking this up).

flocondetoile’s picture

Hi Joachim,

Thanks for you nice module.

I need to use reference option limit on taxonomy term field inside a profile2 entity.

I port your patch on the latest dev version (7.x-1.4+2-dev) and made some modifications to make it working with the ajax trigger.

This patch need some work yet to be more robust. It's a first attempt.

With this patch, reference option limit works fine now inside a profile2 entity, but i have yet some issues I don't understand.

If i select only one value in the field matching, then all is OK. But if i select more than one value (so in case of a multiple select), then I have a fatal error because it seems that the multiple values (returned by the callback ajax) of the field matching are returned in only one array with the tid separated by comma.

    Un choix interdit a été détecté. Veuillez contacter l'administrateur du site.
    Notice : Undefined index: 20,22 dans taxonomy_field_validate() (ligne 1519 dans /srv/web_ulysse/placedesconseils/modules/taxonomy/taxonomy.module).
    Notice : Trying to get property of non-object dans taxonomy_field_validate() (ligne 1519 dans /srv/web_ulysse/placedesconseils/modules/taxonomy/taxonomy.module).

In fact, the form_state['values']['prodile_bundle'] contain this elements

field_term_matching (Array, 1 element)
    und (Array, 1 element)
        0 (Array, 1 element)
            tid (String, 5 characters ) 20,22

Whereas it should be

field_term_matching (Array, 1 element)
    und (Array, 1 element)
        0 (Array, 1 element)
            tid (String, 5 characters ) 20
            tid (String, 5 characters ) 22

And the form_state['triggering_element']['#value'] contain

#value (Array, 1 element)
    20,22 (String, 5 characters ) 20,22

Whereas it should be

#value (Array, 1 element)
    20 (String, 5 characters ) 20
    22 (String, 5 characters ) 22

I'm trying to debugging but for now seems that I'am blocked.

Any idea ?

flocondetoile’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new11.41 KB

the patch.

joachim’s picture

Thanks for looking into this!

> . But if i select more than one value (so in case of a multiple select), then I have a fatal error because it seems that the multiple values (returned by the callback ajax) of the field matching are returned in only one array with the tid separated by comma.

I've just tested this behaviour with nodes, and I get the same problem. So it's an unrelated bug -- file a new issue for that :)

This module was originally built with the controlling field as a single-valued field. I've never tried it with a multi-valued field there, so I imagine there will be work to be done.

I'd suggest you change your fields on profiles to be the baseline configuration -- a single-valued select controlling radios. If you can get that working, then I think we can say we've fixed Profile2 support.

flocondetoile’s picture

Thanks for the prompt feedback.

I've just tested this behaviour with nodes, and I get the same problem. So it's an unrelated bug -- file a new issue for that :)

Hu !? I've just tested latest dev version with nodes, and it's work fine with a select multiple field for the matching element (test with a "Reference to a term" field type).

Options of the field limited are relevant according to the values selected in the field matching.

I've just tested too the patch #3 on a simple node and this works fine too. Need some test with some entity reference field.

What I do not understand is why, and how, on hell, the form is updated with values concatened of the matching field whereas only the limited field is returned with the ajax callback !? This issue seems occur only on profile2 entity.

joachim’s picture

> Hu !? I've just tested latest dev version with nodes, and it's work fine with a select multiple field for the matching element (test with a "Reference to a term" field type).

Huh. It's working for me now! It wasn't earlier on!

flocondetoile’s picture

Lol :-)

Look good that we have same behavior !

Have you got an idea of the reason why tids aret passed to form in a single array, separated by comma, instead of an array of array ?

Do you process these data somewhere ?

EDIT : after read all the code, it seems that reference_option_limit don't process these data anyway.

flocondetoile’s picture

Well,

I test the patch on a clean install and on a fresh installed profile2 entity.
It's works very fine, even for multipe select field.
So i must have a conflict with another module on the site i'm working on :-(

flocondetoile’s picture

Hi Joachim,

I've just tested this behaviour with nodes, and I get the same problem. So it's an unrelated bug -- file a new issue for that :)

I Just realize that you succeed to reproduce this bug. Can you tell more about the context you've got same errors ?

joachim’s picture

I can actually still reproduce it on another test site! What's even weirder is that both this and the one that's working are running identical code for this module -- it's symlinked in!

I can't work out what's different between the two. taxonomy_field_validate() is receiving a badly formed $items, but I don't see how ROL can be responsible for that!

flocondetoile’s picture

I succeed to reproduce the bug on the site where it's work fine.
If you have in the form (profile2 or node) a file (or image) field widget (and soo with some ajax), then the error occurs.

joachim’s picture

> If you have in the form (profile2 or node) a file (or image) field widget (and soo with some ajax), then the error occurs.

Same here!
Thanks for figuring this out! IIRC there's an issue for that already.

flocondetoile’s picture

If you refer to this issue https://drupal.org/node/2006798
It's not the same use case. And the dev version have already your patch published in this issue.

joachim’s picture

Rdnala’s picture

Patch #3 works well with Profile2, but it doesn't support miltiple (chain) referencing fields. Patch #21 from Support one field changing 2+ fields works with chain referencing fields, bit doesn't work with Profile2.
Can anybody join these patches together to get completely working solution?

joachim’s picture

Status: Needs review » Needs work

The patch here applies, but it's got lots of whitespace errors and unrelated changes.

If someone can take care of that, I can commit it. Then the patch at the other issue can get rerolled.

@Rdnala: You shouldn't be working off patches anyway. The purpose of patches is to get committed, not be a shopping list for people to fix their code with.

joachim’s picture

Status: Needs work » Needs review

Not sure why this patch isn't testing. Let's set it back to need review and see if that triggers the testbot.

The last submitted patch, 1: 1814316.reference_option_limit.profile-2-wip.patch, failed testing.

joachim’s picture

Status: Needs review » Needs work
flocondetoile’s picture

Status: Needs work » Needs review
StatusFileSize
new10.42 KB

I join the patch #3 cleaned (no more dsm fucntion). Let's the bot test it.

Rdnala’s picture

@joachim: I need a module to fill 3 chain referencing fields (A->B, B->C) in Profile2, and Reference field option limit is the only (and great!) module I found. Unfortunately, nor stable version, nor current dev doesn't work as expected, so I'm trying to work with dev and patches. I don't see another way right now :(

dariogcode’s picture

#20 works very good. I'm using profile2, and after applied patch errors gone and everything is working ok. Thanks @flocondetoile.

dariogcode’s picture

I tested with other modules and reference option limit have problem in general with modules that attach fields or forms to an entity form. Also there are multiples patch and not well stablished way to implement each one. Do you have some like a roadmap?

joachim’s picture

If you mean multiple patches on this one issue, then generally the latest patch is the one to consider, unless the comments say otherwise.

> not well stablished way to implement each one

Not sure what you mean by this.

> Do you have some like a roadmap?

Nope. I have very little free time at the moment. So it's a case of whichever issues get pushed forward by contributors get my attention. If you feel this project needs a roadmap, feel free to start a new issue for one, and invite people to discuss what they feel their priorities are.

I'm in the process of making a test module for use with Profile2, so I'll be in a position to test the patch myself soon.

joachim’s picture

Status: Needs review » Needs work

Patch works, but needs a clean-up. There are loads of unrelated changes in it.

dariogcode’s picture

thanks for answer my comments.

About multiples patchs I mean some patch that need to be inlcude in dev if was tested properly, for example

#2035157: Limiting options in views exposed filters with ajax: https://www.drupal.org/files/issues/reference_option_limit-2035157_10.patch
#1814316: This one, in this thread: https://www.drupal.org/files/issues/reference_option_limit-support-profi...
#2239831: Replace form_alter with form_attach: https://www.drupal.org/files/issues/reference_option_limit-replace-form-...

I know that need to be tested properly, but my concern is that we can be overwriting something with patch that is neccesary or cover other issue.

And specfically about this patch, I have problem in two scenarios:

1. When implementing a limited field option in the profile
2. When using other ajax elements, for example in a form with two entities (node + profile). The special case of image field I tested, where doesn't allow me to upload images, when disabled one of the form, it works.

As mentioned early, this module appear not handle well when attaching forms to an entity, I see in some cases it is because the field parent isn't recognized, the module doesn't identify the corrent "tree" in form when doing ajax request/responses.

I really appreciate your time and I want to collaborate, so anything I can do to make this work, please let me know

joachim’s picture

> I know that need to be tested properly, but my concern is that we can be overwriting something with patch that is neccesary or cover other issue.

That's a fair point. This issue and #2239831: Use hook_field_attach_form() instead of hook_form_alter(). overlap. Whichever one gets in first will cause the other one to need a reroll, and a very careful one at that.

Regarding causing regressions, this is why we have tests :)

> 2. When using other ajax elements, for example in a form with two entities (node + profile). The special case of image field I tested, where doesn't allow me to upload images, when disabled one of the form, it works.

How are you making your multiple entity form? Do we need to consider writing tests that use https://drupal.org/project/multiple_entity_form ?

Does the patch fix the problem for you in both scenarios, just one, or neither?

joachim’s picture

Here's a patch with just the tests. This will fail tests :)

joachim’s picture

Status: Needs work » Needs review

Oops, need to change the status so the testbot sees it.

Status: Needs review » Needs work
dariogcode’s picture

Thanks for share this https://drupal.org/project/multiple_entity_form, It is new for me.

I don't know well about test, so I'm a bit lost there, but I can try different patch to find the better combination. I will try to setup a fresh install with different settings and try to combine my forms.

I'm using https://www.drupal.org/project/inline_registration and https://www.drupal.org/project/profile2, or combinations. My main goal is to have a node form with user registration. Thinking better I guess I had 3 forms, the node forms, the user register form, and the attached profile2 form, a worse combination.

Inline registration add the user form in the node tree $form['register']['form'] and the profile add in $form['profile_profile_name']. And the errors becomes when you use reference_option_limit in those other form (profile entity or even user fields).

I'm not sure multiple entity forms will work with user registration, because the username and pass aren't part of the user entity form, probably doesn't apply for me.

joachim’s picture

Status: Needs work » Needs review
StatusFileSize
new14.77 KB

Here's the patch at #20 cleaned up with all the unrelated changes removed, plus the tests.

BTW this patch and the patch at #2239831: Use hook_field_attach_form() instead of hook_form_alter(). merge fine, though it does look like the other issue's patch breaks the fix for profiles somehow!

Status: Needs review » Needs work

The last submitted patch, 32: 1814316-32.reference_option_limit.profile2-form.patch, failed testing.

Anonymous’s picture

It would be great to get this functionality working. Let me know if I can help.

joachim’s picture

Please review the patch. Try the tests locally -- I suspect the failure is because we're adding a test module and the testbot doesn't like that.

joachim’s picture

Status: Needs work » Fixed

Let's get this committed and a new release out :)

  • joachim committed 670b6e7 on 7.x-1.x authored by flocondetoile
    Issue #1814316 by flocondetoile, joachim: Fixed to work with Profile2...

Status: Fixed » Closed (fixed)

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

murfi’s picture

thank you for your work

i still have two issues:
1. i'm using the module in commerce checkout; i have a form with billing address and shipping address and both have fields with similar names; i have rebuilt the tree in $form_state['reference_option_limit'] and i have extended the wrapper name with the parents names to keep them distinct
2. there's also a checkbox which makes shipping address the same with the billing address; to keep the functionality, the function reference_option_limit_field_widget_form_alter must not bailout too early even if the ajax call does not concern it

i only tested the patch in this particular case