Problem/Motivation

For a use case of mine I require the basic UI of the simple inline entity form widget provides, with the only addition that you are able to select between a few target bundles.

Proposed resolution

Allow the simple inline entity form widget to work with multiple target bundles by (if the field supports referencing multiple bundles) providing a dropdown in which you can choose the desired target bundle. The inline entity form is dynamically rendered based on the selection you make:

IEF Simple widget with multiple target bundles

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

rp7 created an issue. See original summary.

rp7’s picture

Title: Allow the simple widget to work with multiple target bundles » 3200124-simple-widget-multiple-target-bundles
StatusFileSize
new17.9 KB

I wasn't sure if this should go in a contrib module or directly in the inline_entity_form module. I decided to go the inline_entity_form module for now & hear out your opinions.

The only doubt I have with the current solution is that it re-applies field values of fields with the same name when switching bundles. Could be a bonus? Unsure.

Merge request opened & attaching as a patch as well.

rp7’s picture

Title: 3200124-simple-widget-multiple-target-bundles » Allow simple widget to work with multiple target bundles
geek-merlin’s picture

Thanks raf for steppung up, doing this contribution, and making such a nice gif for it ;-). And test coverage, yay.
I like the feature a lot, but do't have the time today to do a thorough review. Stay tuned.

geek-merlin’s picture

Status: Needs review » Needs work

@rp7: I scanned the patch, and it looks like some of the changes are unrelated. Is this possible? Can you re-check?

Also, can you make an issue fork and push to it so we get gitlab review bliss? Thanks!

https://www.drupal.org/docs/develop/git/using-git-to-contribute-to-drupa...

rp7’s picture

Updated fork with latest commits in 8.x-1.x + removed the "container-inline" attribute (this was - unintended - copy/pasted from the complex widget).

@geek-merlin

I scanned the patch, and it looks like some of the changes are unrelated. Is this possible? Can you re-check?

Could you elaborate a little more? AFAICT every change is needed.

rp7’s picture

I noticed an issue with the current implementation in combination with a multi-value field in the inline entity form (the "Add more" button didn't do anything). The active bundle not (always) being correctly derived was the culprit.

rp7’s picture

rp7’s picture

Made a few minor improvements to the select-element for when the reference field is required.

giorgosk’s picture

I have recreated the patch for latest dev version / 8.x-1.0-rc10 but because of #3270348: Regression from #2901158 this patch is mostly untested.

rp7’s picture

Re-rolled against latest dev + fixed an issue where the bundle options weren't sorted by their weight (defined in

target_bundles

setting).

rp7’s picture

Re-rolled against latest dev + fixed an issue with the incorrect label being used in the required error message.

rp7’s picture

StatusFileSize
new17.64 KB
new678 bytes

Typo in previous patched. Sorry for the noise.

rp7’s picture

The inline entity form input is now also reset when changing the bundle. This way default field values are correctly applied.