Hello friends,

In the node add/edit form I have an entity reference field that uses a view with 2 contextual filters for node references.
Now I have 2 fields (both radio groups) which should control the arguments (radio 1 values should become argument 1 and radio 2 values become argument 2).
So, a click on the radio buttons should update the arguments and load the updated entity reference field on the fly. The entity reference field is a radio group as well.

Unfortunately, I couldn't even find the arguments with dpm()/kpr() in the $form/$form_sate output.

Has anyone an idea on how to achieve that?

Help is much appreciated.

Thank you very much!

Comments

design.er created an issue.

ctrlADel’s picture

I just tried to do something very similar and I've come to the conclusion that it isn't possible. The view argument settings are loaded in directly from the field info so there aren't any hooks that can be used to modify the value before it gets passed to the view.

Though #2010898: Use tokens for entity selection view arguments looks promising for my needs.

design.er’s picture

Thanks for your reply.
I don't know why but the promising patch didn't work in my case.

Anyway, in the meantime I've found a workaround for the ajax filtering:
01) Install the module Reference field option limit.
02) On the entity reference field settings page:
02.01) choose Mode: Simple (unfortunately it doesn't work with Views mode) and of course choose the desired target bundle as usual.
02.02) activate the checkbox "Limit this field's options according to matching field values" and choose the fields that the newly installed module should compare with the fields from the target bundle.

So, every time you use one of the fields that you've declared as "matching fields" (in step 02.02) in your node form, they will trigger an update of the entity reference list per ajax.

I hope, this will help somebody.

design.er’s picture

But this is just a workaround - not a (satisfying) solution.
I still hope, it will be possible to alter the views arguments some day. That would be a clean approach and empower to update the field values in custom ajax callbacks.