I see this as a todo in code, so I thought I'd take a stab at it. Attached a patch that gets this working for me with both nodes and users. Anyone care to test it with other entities?

I feel like what I did in entityreference_browser_field_picker.inc is a total hack. But I couldn't think of a simpler way to figure out the entity type rather than looping through all the entities defined on the site, looking for a matching base table.

Comments

mcarbone’s picture

This is working for me. I think checking base_tables is fine, although I'm pretty sure there's a way to pull the entity_type from the view itself, so you might want to dive into into that recursive beast.

Jackinloadup’s picture

This worked for me with users

davidseth’s picture

@ohthehugemanatee, Thanks for the patch and thanks @mcarbone & @Jackinloadup for testing. I will commit the patch this weekend.

andyg5000’s picture

I'm getting the following error using this patch for user entityreference. I'm not sure if it's related to this patch, the module, or the fact that I have 2 widgets on the same page.

Fatal error: Cannot create references to/from string offsets nor overloaded objects in /DRUPAL/includes/common.inc on line 6443

This might need to be a new issue, but figured I'd start here since I only get that error when attempting to assign users with the widget.

davidseth’s picture

@andyg5000, can you try it with just one widget on the edit page?

andyg5000’s picture

@davidseth,
I originally had an entityreference(node) and entityreference(user) widget on the same page. I'm only having problem with the user one when attempting to assign a user to the reference. This happens with only the 1 user reference as well. It looks like it's not even getting to the validate handlers before it crashes. I'm debugging now and will post an update as soon as I can.

andyg5000’s picture

Now it's happening with both widgets. The values that are getting passed to drupal_array_get_nested_value (in field/field.default.inc) are as follows:

[field_assigned_to] => Array (
            [und] => 185,160
        )

 [field_assigned_groups] => Array (
            [und] => 4098
        )

when they should be (roughly):

[field_assigned_to] => Array (
            [und] => array(
                 [0] => array(
                 [target_id] => 185
              )
           )
        )

I see that the validate handlers should set this structure up, but for some reason they aren't firing.

andyg5000’s picture

Status: Active » Reviewed & tested by the community

Doh! ignore my issues. I'm dealing with an inherited project and some other module was fubaring the field_assigned_to field before submission. It's working great now!

davidseth’s picture

@andyg5000 Great, well it has worked well for others as well. I will go ahead and commit this now.

Cheers,

David

davidseth’s picture

Status: Reviewed & tested by the community » Closed (fixed)

Alright patch committed. Thanks @ohthehugemanatee and everyone else for testing.