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,

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

timmarwick’s picture

Indeed, 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...?

jsacksick’s picture

Apparently, 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).

gaele’s picture

Category: Support request » Bug report
gaele’s picture

Title: Passing ids from entityreference into view not working for me » Passing ids from entityreference into view not working
malovanets’s picture

This 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 :)

tedbow’s picture

Version: 7.x-2.0-alpha2 » 7.x-2.x-dev
Status: Active » Needs review
FileSize
3.69 KB

Ok, 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.

tedbow’s picture

Status: Needs review » Needs work

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

  1. Once the modal has been opened once the entity ids will likely have changed but this will not be reflected
  2. The user can also manually uncheck entities via the checkboxes without opening the modal. This will not be reflected either.

I explored whether this could be solved by inserting javascript code here

$('.ervw-add-items').bind('click',
      function() {

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.

  1. Don't use 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 broken
  2. The other way would be to not use ctools_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?

__cj’s picture

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

__cj’s picture

Oops

__cj’s picture

malovanets’s picture

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

__cj’s picture

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

gaele’s picture

Status: Needs work » Needs review
__cj’s picture

Found a problem with the values not being saved. The attached fixes this.

Chris

__cj’s picture

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

__cj’s picture

Status: Needs review » Needs work

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

__cj’s picture

Status: Needs work » Needs review
FileSize
6.81 KB

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

graker’s picture

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

jsacksick’s picture

Status: Needs review » Needs work

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

  • Commit 8615ea3 on 7.x-2.x by jsacksick:
    Issue #2203703: Implement the "Pass selected entity ids to View" + code...
SantVim’s picture

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

  • Commit 659d9c8 on 7.x-2.x by jsacksick:
    Follow-up to #2203703: Fix some issues when multiple widgets displayed...
jsacksick’s picture

Status: Needs work » Needs review

Thanks a lot for your feedbacks Dhamub, can you test again? I committed a fix.

SantVim’s picture

Hey, 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.

jsacksick’s picture

Why didn't you select the user in the first place?

SantVim’s picture

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

jsacksick’s picture

Status: Needs review » Fixed

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

SantVim’s picture

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

graker’s picture

After 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".

Status: Fixed » Closed (fixed)

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

azovsky’s picture

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

sriharsha.uppuluri’s picture

Issue still exists values are not being passed

sriharsha.uppuluri’s picture

Status: Closed (fixed) » Active
SantVim’s picture

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

sriharsha.uppuluri’s picture

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

DrDam’s picture

Status: Active » Fixed

work 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

Status: Fixed » Closed (fixed)

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

RKopacz’s picture

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

RKopacz’s picture

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

funkeyrandy’s picture

i 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];

picacsso’s picture

To 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"