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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bojanz’s picture

Can you edit your reference field and just select only one allowed bundle?
That will cause the bundle dropdown to disappear.

hanspln’s picture

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

dwalker51’s picture

I have the same issue.

PedroMiguel’s picture

I have also the same need

Rob C’s picture

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

    // Make sure that if we are rendering a view we fake
    // setting a bundle. It's not used, and only exists to suppress
    // the rendering of the bundle select on the node form.
    if (!empty($field['settings']['handler_settings']['view'])) {
      $settings['bundles'] = array(array());
    }

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.

westie’s picture

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

mtoscano’s picture

I 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

Dave Reid’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
Status: Active » Needs review
FileSize
1.34 KB

Here's a patch that integrates with node views to limit the bundle selection field.

Dave Reid’s picture

Revised patch #8 to be correct for bundle values.

mtoscano’s picture

Issue summary: View changes

This 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

mtoscano’s picture

Status: Needs review » Needs work
whthat’s picture

Update patch to work with 7.x-1.5

whthat’s picture

Status: Needs work » Needs review
freality’s picture

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

vaccinemedia’s picture

Patch #12 works a treat :)

pmchristensen’s picture

Corrected patch file - changed paths to files to be from module folder instead of from drupal root folder.

nevergone’s picture

#16 is works well!

eneko1907’s picture

#16 works for me too - thanks for the update

Sumi’s picture

#16 works for me as well.

Deciphered’s picture

Status: Needs review » Reviewed & tested by the community

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

bojanz’s picture

Status: Reviewed & tested by the community » Needs work

I can't commit a patch that works only for nodes.
Get the entity keys, search for the bundle key, make it generic.

FeyP’s picture

Status: Needs work » Needs review
FileSize
2.58 KB

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

Mołot’s picture

Patch by FeyP Worked like a charm for me.

Mołot’s picture

Status: Needs review » Reviewed & tested by the community
jweirather’s picture

Please ignore, posted to the wrong thread.

jweirather’s picture

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

LonitaD’s picture

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

nevergone’s picture

morsok’s picture

Worked for me too, i'd love to see this commited :)

eneko1907’s picture

revised patch at #22 Works for me too - would be great to see this patch moved to dev. THANKS!

sch2’s picture

#22 worked nicely. Thanks! I'd also like to see it committed to dev

gilsbert’s picture

#22 is working. May it be commited?

friera’s picture

#22 is working. Thanks!

hkirsman’s picture

nessunluogo’s picture

#22 solved my problem. Will it be committed?

goron’s picture

Confirming also that this works and should be committed

prografr’s picture

#22 also worked for me.. thanks alo @FeyP

ray17n’s picture

#22 also works for me. Thanks.

ashedryden’s picture

#22 tested and works on 7.x-1.8

tucho’s picture

The patch on #22 works for me as well.

AlfTheCat’s picture

#22 works like a charm. Thanks!

whthat’s picture

Applies to 7.x-1.9 cleanly and still relevant

smurfxx’s picture

#22 works!

  • ram4nd committed 7775844 on 7.x-1.x
    Issue #1872316 by Dave Reid, whthat, westie, freality, pmchristensen,...
ram4nd’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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