Hi there,
I've just found a "triple" bug within the IEF integration. The code in entity_browser_entity_form_inline_entity_form_reference_form_alter() currently breaks for having at least one of the 3 following use cases:
* The target entity type does not have bundle support: getTargetBundle() returns NULL in this case -> we have to use the target entity type ID instead
* The entity reference field is a base field -> you can't call $instance->get('cardinality') on base fields. But there's a nicer dedicated getCardinality() anyway, which can be used in both cases
* The entity form display is not stored in the database --> we have to follow the approach of the (deprecated) entity_get_form_display() function and create the form display on the fly
So, these are basically three different tiny issues, but I think it's easier to keep it in one issue report and patch.
I have already prepared a patch, and will also propose a PR on Github
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | 2897622-12.patch | 4.94 KB | nuez |
| #6 | interdiff-3-4.txt | 2.49 KB | oknate |
| #6 | fix_bundleless_and_basefield_support-2897622-4.patch | 1.89 KB | oknate |
| #5 | fix_bundleless_and_basefield_support-2897622-3.patch | 2.44 KB | ccyrille |
| #2 | fix_bundleless_and_basefield_support-2897622-2.patch | 2.44 KB | agoradesign |
Issue fork entity_browser-2897622
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
Comment #2
agoradesign commentedso here's the patch
Comment #3
agoradesign commentedHere's the link to the PR: https://github.com/drupal-media/entity_browser/pull/156
Comment #4
ccyrille commentedj'ai le même problème avec la version 8.2. Le patch marche pour moi.
Thank!
Comment #5
ccyrille commentedPatch for 8.x-2.1
Comment #6
oknateI believe it's possible to grab the form display from FormState storage:
This will simplify the code a bit.
Comment #7
oknateComment #8
johnchqueBug reports should go always against the dev branch.
Comment #9
dwkitchen commentedI had all these three requirements in one use case
✅ Reference field was a base field
✅ Reference entity type was not bundled
✅ Form was not stored in the DB
All working as expected with the patch.
Comment #10
nuezI think the patch in #6doesn't quite solve this issue, at least not for me.
This won't work for multiple levels of embedded inline entity forms. The 'form_display' in storage applies to the root entity of the form.
This won't work for base fields, because the $instance variable might be of type BaseFieldDefinition, which doesn't have any information about the bundle in it.
Instead of looking at the field instance (base field or config field) we should look at the parent entity. However there seems to be no easy way to find the parent entity of the field. My suggestion is to propose a patch for the inline entity form that adds the 'parent' to the 'widget state' that is saved to the form_state storage by IEF, so we can use it here.
Comment #12
nuezThis patch needs to be used in combination with the patch provided in: https://www.drupal.org/project/inline_entity_form/issues/3253939
Comment #13
nuezComment #14
anul commentedLast added patch/change works fine. We need to improve a code in terms to move this issue in Needs Review.
Comment #15
twodNot sure if this belongs in this issue, but this line makes an assumption there are target bundles, which may not be the case so we get a warning here.
Comment #16
s_leu commentedAs mentioned in #12, the patch here combined with the one of the MR in #3253939: Add the parent entity to the widget state to fix base fields for Entity Browser fix a problem I encounter when using the an entity browser in a field with inline entity form complex formatter. Without the patch I get the error message mentioned in https://www.drupal.org/project/inline_entity_form/issues/3253939#comment-14478254
Also regarding #15, this seems to have been addressed in another issue: #3283482: Entity browser inline form widget throws warning for bundle-less entities
Comment #17
anybodyPlease turn this into a MR if still relevant and address the comments above.
Comment #19
berdirIt still is relevant, but it's also still postponed on the IEF issue, it only works when combined with that and that's a hard blocker.
There was already an MR, I rebased it, conflicted only on coding style fixes.