Hi there,
I've spent the last couple of hours trying to understand why passing entity ids into the view (for the purpose of excluding existing items) is not working for me. The view works fine when I manually enter the ids to exclude in the views preview section, but these arguments are not being passed in when the modal is opened in situ, via the 'add items' button.
This is not so much a bug report, at least at this stage, because I'm not sure if it's a problem with the module or interference coming from elsewhere.
Could you advise me where in the code these entity id arguments are supposed to be passed into the view, so I can work on debugging the issue in my context? I've not been able to discover this for myself.
Cheers,
Comments
Comment #1
timmarwick CreditAttribution: timmarwick commentedIndeed, it appears the 'pass_argument' setting only ever gets input, but is never again referred to to influence how the widget/view should behave. I can't figure this out. It really looks like this feature is not implemented anywhere in the code...?
Comment #2
jsacksick CreditAttribution: jsacksick commentedApparently, this feature is not implemented in the code, we only have to pass the ids to the view by calling set_arguments (then the view should have a contextual filter to make that work).
Comment #3
gaele CreditAttribution: gaele commentedComment #4
gaele CreditAttribution: gaele commentedComment #5
malovanets CreditAttribution: malovanets commentedThis feature was inherited from the 1.x version but not implemented yet. Developers who faced a particular use case are welcomed to commit a patch :)
Comment #6
tedbowOk, Here is a start to at the patch.
It works now when you first open the modal window it passes the argument to the View.
The problem is that entity ids are set when the form is first built. So if you open the modal window a second time it still passes the same entity ids.'
There would probably need to be some changes to entityreference_view_widget.js to update the modal link with new selected entity ids.
Any help on that would be appreciated.
Comment #7
tedbowOk after further testing I don't think my approach will work very well. The problem is that it sets the ids when the form is first created. This will not work for 2 reasons.
I explored whether this could be solved by inserting javascript code here
To pass the current values of the checkboxes but from my testing it seems
entityreference_view_widget_modal
is already called so it is too late.There seem to be 2 ways to solve this.
ctools_modal_text_button
to open the modal but make a form that includes the checkboxes and the add more button. Configure the form to open the modal on submission then you can access the current state of the checkboxes. There is some discussion on how to do this here #1482968: Open modal on form submission is brokenctools_modal_text_button
but to bind our own function to open the modal which would pass on the ids.I like #1 if it could work because it lets ctools modal do most of the work.
Any thoughts?
Comment #8
__cj CreditAttribution: __cj commentedThe attached patch changes the 'Add more' link into a button which submits the form to the model window.
I've built on the code from #6 to the process the submitted form values.
It uses the approach discussed in https://drupal.org/comment/8186333#comment-8186333.
Chris.
Comment #9
__cj CreditAttribution: __cj commentedOops
Comment #10
__cj CreditAttribution: __cj commentedComment #11
malovanets CreditAttribution: malovanets commented$form = ctools_modal_form_wrapper('cpd_report_review_node_form', $form_state);
What is cpd_report_review_node_form ? Seems like you left there some hardcode.
Comment #12
__cj CreditAttribution: __cj commentedThere was a problem which prevented the form from being submitted. Because the form was being submitted to the modal when you went to actually submit the form it wasn't being accepted.
This patch also removed the hardcoded form_id (Sorry about that!).
Chris.
Comment #13
gaele CreditAttribution: gaele commentedComment #14
__cj CreditAttribution: __cj commentedFound a problem with the values not being saved. The attached fixes this.
Chris
Comment #15
__cj CreditAttribution: __cj commentedSmall refactor...
For #2177215: Selected items are not checked on reopening modal we'll need to access the submitted values.
The updated patch breaks getting the submitted eids into it's own function, and caches it.
Comment #16
__cj CreditAttribution: __cj commentedIf you put an exposed filter form on the view, and apply a filter the ids are lost.
After thinking about it a little more I'm not sure passing the ids directly to the view is the way to do this - it will prevent you adding other contextual filters. I think creating an 'argument default' plugin might be better.
Comment #17
__cj CreditAttribution: __cj commentedThis patch adds a view argument default plugin. To use this on the options of the contextual filter, in the 'WHEN THE FILTER VALUE IS NOT AVAILABLE' section, select 'Provide a default value', and select the 'Entity Reference View Widget - Selected Entities' option.
This makes the 'pass_argument' option redundant - if you want the value passed to the view just use the view argument plugin - so this patch removes it.
This solves the exposed filter problem, as described above, as views deals with storing the value within the exposed filter form, when passed to views in this way.
Comment #18
graker CreditAttribution: graker commentedI tried patch #17 against the latest dev and got EntityMalformedException: Missing bundle property on entity of type node in entity_extract_ids() at line 7721. The error occurs when I click "Add items" button to open the widget.
Without the patch, widget was working, though previously selected entities weren't checked when reopening widget.
Comment #19
jsacksick CreditAttribution: jsacksick commentedThe code has dramatically changed since your patch, I'm afraid it has to be rerolled... We could use the entity_ids coming from form_state (it will contain the unchecked checkboxes but I think it's ok since we don't want them to be in the modal again (it's already there). It should be doable pretty easily. I'm also wondering what to do in case the view doesn't contain any result? Don't open the modal? Display a message? Let the view handle that?
Comment #21
SantVim CreditAttribution: SantVim commentedWorking nice but getting an error with 7.x-2.0-beta2+1-dev
Notice: Undefined index: cardinality in entityreference_view_widget_ajax() (line 358 of
Also if i got two fields in a form that uses the widget the entities(in my case users) selected in the first field are hidden in the second field too.
Comment #23
jsacksick CreditAttribution: jsacksick commentedThanks a lot for your feedbacks Dhamub, can you test again? I committed a fix.
Comment #24
SantVim CreditAttribution: SantVim commentedHey, tested it on up to 8 fields in a node form. Solid and no errors. :)
A minor thing though with exposed filters you search for a user or node, select it and search for another one the previous selection is lost.
In my case i have a view of users with exposed username, city & state filters. I search for a user by name select them and when i search for another user the previous user is not selected anymore.
Comment #25
jsacksick CreditAttribution: jsacksick commentedWhy didn't you select the user in the first place?
Comment #26
SantVim CreditAttribution: SantVim commentedYou mean to ask why i didn't submit the selected user right?? Looks i wasn't clear on the issue.
In a multivalue field with I open the modal and search for users in the city exposed filters ( lets say london ) and select them (like 3 users), now in the same modal without submitting if i change the city (to Paris) and select the users ( 2 users) and clear the exposed filter (back to ANY city) no users are selected.
Right now i should submit the selected users and open the view again to select another set of users from another city or one should browse the whole list and select and submit (imagine a list of few thousand user or nodes) without using the exposed filters.
Comment #27
jsacksick CreditAttribution: jsacksick commentedYou can just uncheck the "Close modal window after submitting the items" option, then the modal won't be closed and that's it? You select 3 users, you click on submit, and then you continue adding other items, anyway, it's out of the scope of that issue.
Comment #28
SantVim CreditAttribution: SantVim commentedWill try what you suggested and Sorry definitely not related to this issue.
Edit:Yes select the entity and submit works fine like you said. Thanks.
Comment #29
graker CreditAttribution: graker commentedAfter updating, the issue for me is fixed: items selected before are not present in the view. I had to resave the view and field settings though.
As for what to do when there are no more items to show, I suppose it's all right to show the view anyway so user could set up the "No results behaviour".
Comment #31
azovsky CreditAttribution: azovsky commentedShould I apply any patches from this discussion/issue?
Since the error is still there for me (using 7.x-2.x-dev 2014-May-23).
thanks!
Comment #32
sriharsha.uppuluri CreditAttribution: sriharsha.uppuluri commentedIssue still exists values are not being passed
Comment #33
sriharsha.uppuluri CreditAttribution: sriharsha.uppuluri commentedComment #34
SantVim CreditAttribution: SantVim commented@sriharsha.uppuluri It works gr8 for me, do provide more info and steps to reproduce your issue. Just saying it's not working and changing closed issues to active won't be helpful anyone in my opinion.
Comment #35
sriharsha.uppuluri CreditAttribution: sriharsha.uppuluri commented@Dhamub I'm using drupal 7-3.4 and installed entity refernce view widget 7.x-2.0-rc3. As mentioned in documentation followed the same steps but the selected values are not populated as selected. The reason why i have opened the ticket is checked with dev version and applied few patches eventhough its not working for me, so i have opened the ticket.
Comment #36
DrDam CreditAttribution: DrDam commentedwork for me.
@Dhamub : Are you sure, you had adding "nid" contextual filter in the view ?
But I don't see what I need to do for "auto-checking" values in the modal
Comment #38
RKopacz CreditAttribution: RKopacz commentedI'm not sure this can be marked as fixed, I'm struggling with this same issue now with the most recent versions release & dev. Will be testing it on a clean drupal install to see if there isn't a conflict with other modules.
Comment #39
RKopacz CreditAttribution: RKopacz commentedUpdate to #38:
I just tested ervw on a clean install of Drupal, with just the essential modules needed, and it works (the selected content IDs are being filtered out of the selection list). So that means somewhere, there must be a module I have installed which is causing this not to work.
Will investigate and report back when I find out which module is the culprit, for the benefit of others. Stay tuned . . .
Comment #40
funkeyrandy CreditAttribution: funkeyrandy as a volunteer commentedi got it to work another way, using arguments from the referring url....could be useful in some use cases
$ref=explode('/',$_SERVER["HTTP_REFERER"]);
print $ref[6];
Comment #41
picacsso CreditAttribution: picacsso as a volunteer commentedTo simplify matters...
1. Make sure that you're using the latest version of this module.
2. Make sure that "Pass selected entity ids to View" on your entity reference view widget field is checked. (Keep "Display all results for the specified field" selected)
3. Make sure that the view you're using is implementing a Contextual Filter of "Content:Nid". Also, please make sure to expand the "More" tab under the contextual filter and checkbox both "Allow multiple values" and "Exclude"