Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm attaching an IEF to a contact field on a nodetype, but I want to filter it to nodes by logged in users.
The views works fine with other widgets, but with IEF one has to chose the bundle and then add node. I would like to force select which bundle gets created (as is when using simple.)
Comment | File | Size | Author |
---|---|---|---|
#22 | 1872316-ief-bundle-selection-erv-22.patch | 2.58 KB | FeyP |
#12 | 1872316-ief-bundle-selection-node-view.patch | 1.4 KB | whthat |
#16 | 1872316-ief-bundle-selection-node-view-corrected.patch | 1.22 KB | pmchristensen |
Comments
Comment #1
bojanz CreditAttribution: bojanz commentedCan you edit your reference field and just select only one allowed bundle?
That will cause the bundle dropdown to disappear.
Comment #2
hanspln CreditAttribution: hanspln commentedUnder entity selection, the "Target Bundles" disappears when you choose to select values from a view instead of "Simple (with optional filter by bundle)"
I have enabled both "Add new" and "add existing", and it's because of the "add existing" I need a view to filter on "by logged in user".
Comment #3
dwalker51 CreditAttribution: dwalker51 commentedI have the same issue.
Comment #4
PedroMiguel CreditAttribution: PedroMiguel commentedI have also the same need
Comment #5
Rob C CreditAttribution: Rob C commentedI have the same case as #2. After some digging, it does seem to work when i filter per view and hard code something like this as a test in i_e_f.module file at line 334 +/- inside the inline_entity_form_settings() function inside the elseif ($field['type'] == 'entityreference') { ... } below everything else in that function.
A bit below this line i read a foreach ($info['bundles'].....)... that 'bundles' isn't set if you use my attempt, so this should just work. At least, the select is gone, and the content displays just fine, filtering is done via Views anyway.
edit: after testing some with the cer module (Corresponding entity references), i notice that when i select a view for selecting entities, cer will stop working. So we do need a bundle and this is not enough.
Comment #6
westie CreditAttribution: westie commented@Rob C Sounds like a good idea to me although I think people may want to select which bundles can be created rather than hard coding.
A views is being used to filter what can be referenced, it should also be responsible for defining which bundles may be created.
I have applied the attached patch for my use case (Taxonomy Terms) (but should be easy to convert for all entity types) and this allows bundles to be selected from within views using the "Taxonomy term: Vocabulary" filter, the selection made here will be reflected in the node edit forms.
Once reviewed if people think the approach used is good then I can roll new patches for node content types etc.
Comment #7
mtoscano CreditAttribution: mtoscano commentedI don't have a user case for Taxonomy, but if you produce a patch for node content type I will be happy to test and report.
I think this feature is important.
Thanks
Comment #8
Dave ReidHere's a patch that integrates with node views to limit the bundle selection field.
Comment #9
Dave ReidRevised patch #8 to be correct for bundle values.
Comment #10
mtoscano CreditAttribution: mtoscano commentedThis patch does not apply anymore against 7.x-1.5 and this feature has not been implement yet.
That means there is no way to make sure that if using a view for the entity selection, only the bundles which are returned by the view are available to create.
Anyone able to port this patch against latest dev version or point to another working patch?
Thanks
Comment #11
mtoscano CreditAttribution: mtoscano commentedComment #12
whthat CreditAttribution: whthat commentedUpdate patch to work with 7.x-1.5
Comment #13
whthat CreditAttribution: whthat commentedComment #14
freality CreditAttribution: freality commentedThe previously attached patches did not work for me because I was referencing entity types other than node. This patch simply tests if the handler is a Entity Reference Selection Handler, and clears the
$settings['create_bundles']
array.I haven't found any ill affects in this approach. EntityReference doesn't require a bundle.
This logic should probably be in
inline_entity_form_settings
. But I could not decipher the impact of that change. If agreed, I can refactor.Comment #15
vaccinemedia CreditAttribution: vaccinemedia commentedPatch #12 works a treat :)
Comment #16
pmchristensen CreditAttribution: pmchristensen commentedCorrected patch file - changed paths to files to be from module folder instead of from drupal root folder.
Comment #17
nevergone CreditAttribution: nevergone commented#16 is works well!
Comment #18
eneko1907 CreditAttribution: eneko1907 commented#16 works for me too - thanks for the update
Comment #19
Sumi CreditAttribution: Sumi commented#16 works for me as well.
Comment #20
Deciphered CreditAttribution: Deciphered commentedPatch works a charm, and while it's a bit of a pain in the butt to have to load and execute a view just to get the bundle filter values, it is a seamless user experience and fixes the issue nicely.
Comment #21
bojanz CreditAttribution: bojanz commentedI can't commit a patch that works only for nodes.
Get the entity keys, search for the bundle key, make it generic.
Comment #22
FeyP CreditAttribution: FeyP commentedAttached is a patch, that uses the same approach as #16, but should work for any entity. I also added a check of contextual filters, if no filter on the bundle is present.
Comment #23
Mołot CreditAttribution: Mołot commentedPatch by FeyP Worked like a charm for me.
Comment #24
Mołot CreditAttribution: Mołot commentedComment #25
jweirather CreditAttribution: jweirather commentedPlease ignore, posted to the wrong thread.
Comment #26
jweirather CreditAttribution: jweirather commentedWorks for me as of the IEF 7.x-1.6 release (dev) as well. Any chance of getting this committed?
The recent update to 1.6 caused the issue for me again and I had to calm the masses, find and reapply the patch.
Thanks all!
Comment #27
LonitaD CreditAttribution: LonitaD commentedPatch in #1872316-22: Can't select a default bundle when using entity reference views works great for me as well. Will this be committed sometime in the future?
Comment #28
nevergone CreditAttribution: nevergone commented#1872316-22: Can't select a default bundle when using entity reference views Tested and works well! :)
Comment #29
morsokWorked for me too, i'd love to see this commited :)
Comment #30
eneko1907 CreditAttribution: eneko1907 commentedrevised patch at #22 Works for me too - would be great to see this patch moved to dev. THANKS!
Comment #31
sch2 CreditAttribution: sch2 commented#22 worked nicely. Thanks! I'd also like to see it committed to dev
Comment #32
gilsbert CreditAttribution: gilsbert commented#22 is working. May it be commited?
Comment #33
friera CreditAttribution: friera as a volunteer commented#22 is working. Thanks!
Comment #34
hkirsman CreditAttribution: hkirsman commentedSame in D8 - https://www.drupal.org/node/2729333
Comment #35
nessunluogo CreditAttribution: nessunluogo as a volunteer commented#22 solved my problem. Will it be committed?
Comment #36
goron CreditAttribution: goron commentedConfirming also that this works and should be committed
Comment #37
prografr CreditAttribution: prografr commented#22 also worked for me.. thanks alo @FeyP
Comment #38
ray17n CreditAttribution: ray17n commented#22 also works for me. Thanks.
Comment #39
ashedryden CreditAttribution: ashedryden commented#22 tested and works on 7.x-1.8
Comment #40
tuchoThe patch on #22 works for me as well.
Comment #41
AlfTheCat CreditAttribution: AlfTheCat commented#22 works like a charm. Thanks!
Comment #42
whthat CreditAttribution: whthat at College of Western Idaho commentedApplies to 7.x-1.9 cleanly and still relevant
Comment #43
smurfxx CreditAttribution: smurfxx commented#22 works!
Comment #45
ram4nd CreditAttribution: ram4nd as a volunteer commented