I have a content type "message" which has a reference to an organic group. The messages also references one or more "document" nodes that belong to that same group.
I want to use the widget to allow the user to select the nodes.
When I set up the view used by the widget and add a contextual filter, the filter value doesn't seem to be available (This display does not have a source for contextual filters, so no contextual filter value will be available unless you select 'Provide default') so I also set "When the filter value is not available".
I choose "Provide default value" but neither "current OG group from context" or "content id from url" gives any result. Using - as a check - a fixed value does give me a result. (The view preview works fine of course when entering the contextual parameter)
The only way for me to solve this is to add an exposed filter for the group, so the user explicitly chooses the group id to which the "message" belongs in order to see the "documents" that are availabe in that group.
Is the issue with "OG context"? Or is it the modal form setup?
Comments
Comment #1
erwin k CreditAttribution: erwin k commentedComment #2
joncjordan CreditAttribution: joncjordan commentedAny solutions?
Comment #3
jsacksick CreditAttribution: jsacksick commentedCan you try to disable the "Pass selected entity ids to View" option? Because when it's enabled, we're calling the
set_arguments
method on the view which is probably causing the issue.Comment #4
hansrossel CreditAttribution: hansrossel commentedThe problem is a bug in the og_context module as the og_context is not available inside ajax calls, there are some patches in the bug report that try to fix this: #1635750: OG Context handler for ajax calls (system, file upload, autocomplete, etc).
You can also not use "nid from url" as an argument in views because the path of the modal is system/ajax.
So inside the function entityreference_view_widget_add_more_ajax($form, $form_state)
print_r(og_context()) is empty.
For node/*/edit pages you could get the nid and gid from the form_state:
Comment #5
hansrossel CreditAttribution: hansrossel commentedComment #6
hansrossel CreditAttribution: hansrossel commentedI have tried the last patch of og_context but could not get a solution with it, so if you have this specific use case where you only use the widget for a view with an organic groups argument set on the group id you could use the following temporary fix/hack until og_context is fixed:
Comment #7
hansrossel CreditAttribution: hansrossel commentedComment #8
jsacksick CreditAttribution: jsacksick commentedThere's normally no need for your hack, you should be able to do that using the
hook_entityreference_view_widget_views_arguments_alter()
.Comment #10
BarisW CreditAttribution: BarisW commentedI fixed this using:
Comment #11
iaminawe CreditAttribution: iaminawe commentedThanks @BarisW - that works great and my view now is aware of the current og context as provided by the nid in the url.
The only problem is now the nids used as a contextual filter to exclude the already selected items does not work. It works correctly if the nid contextual filter is not added but when both are added together then the first time adding works but clicking again to add more just gives a wsod and the following errors in the logs.
Warning: array_key_exists(): The first argument should be either a string or an integer in ctools_get_plugins()
Warning: Illegal offset type in isset or empty in ctools_get_plugins()
Any help to get these 2 contextual filters to play nicely together would be appreciated. Thanks