My question is almost all in the title, is there a way to provide a default value to entity reference field with inline entity form + entity browser enabled ?
In fact I'm trying to find a way to make it work with user entity.
On the Entity Browser "List" tab I add a link to 'user_register_form' then redirect on submission to my node's creation form with the user reference field and the new user ID as parameter.
But I can't find how to properly set the field #default_value.
Seems that there is 2 array to fill :
- $field['widget(]['target_id']['#default_value'] = 'user:[uid]';
- $field['widget(]['current']['items'] which list already selected user.
I'm stuck there. I found in /src/Field/FieldWidget/EntityreferenceBrowser/Widget.php taht 'current' array is filled by displayCurrentSelection method, but I really don't know how to use or mimic this.
Any help is welcome
Comments
Comment #2
handkerchiefany news on this??
i have the same problem like this: https://drupal.stackexchange.com/questions/254593/prepopulate-an-entity-...
Comment #3
lefale commentedI had to implement that kind of functionality in a "generic" sort of way in one of my projects. More specifically, I had to allow any entity reference fields that use the Entity Browser widget to be prepopulated (for any bundle), knowing that the required information would be made available from the query string in the format ?field_name1=id1, etc.
This is what I ended up doing. You can add this in hook_form_node_form_alter() and adapt if needed.
Comment #4
ravi.sidd commentedAny update on this? Can someone please help - ?
I have used entity browser in a custom form but not able to show the image selected after selecting from entity browser. After that when I submit the form not able to retain default value.
Quick help appreciated.