At the moment, we get the potential target bundles like this (in InlineEntityFormMultiple.php):

$target_bundles = isset($settings['handler_settings']['target_bundles']) ? $settings['handler_settings']['target_bundles'] : array();

The problem with this is that if we try to reference user entities, or any entity type that doesn't use bundles, only an empty fieldset is displayed (or if "Allow users to add existing entities." is enabled, the "add" button is not displayed).

Comments

floretan’s picture

Status: Active » Needs review
StatusFileSize
new1.83 KB

Here's a patch that fixes this issue. It uses the fact that when a field doesn't use bundles, $settings['handler_settings']['target_bundles'] is an empty array, but when a field uses bundles and none are set (for example, because the user interrupted the field creation workflow before entering the field settings) $settings['handler_settings']['target_bundles'] is undefined.

Maybe we could get more reliable information by loading information from the entity type, but I'm not sure it's worth the overhead.

The example with the user reference field is just to give an easy way to replicate the bug, there are definitely more realistic use cases (for me, it's a custom entity that needs to be edited from the context of another one).

slashrsm’s picture

This was already discussed in https://github.com/webflo/inline_entity_form/pull/10/files. Main concern in this PR was assuming entity type == bundle for entity types without bundles. I think it is safe to assume that as we have this assumption in other places around core too.

Looks OK to me.

dawehner’s picture

StatusFileSize
new956 bytes

I think this patch is a little bit wrong. It is a false assumption that entity type is always the key.

No target bundles actually mean all bundles.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/src/Plugin/Field/FieldWidget/InlineEntityFormMultiple.php
@@ -134,6 +134,12 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
+    // None allowed target bundles means all of them.

"No allowed..." :P

Other looks good to me, the comment cad be fixed on commit :)

amateescu’s picture

Status: Reviewed & tested by the community » Needs work

Oops, that was a bit hasty. Some manual testing shows that the patch in #3 doesn't work all the way :)

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new1.94 KB

There we go. Did some similar change to

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Cool, that looks better.

  • bojanz committed 4e64b4f on 8.x-1.x authored by dawehner
    Issue #2534320 by dawehner, floretan: Cannot create entities for types...
  • bojanz committed 829ff50 on 8.x-1.x authored by dawehner
    Issue #2534320 by dawehner, floretan: Cannot create entities for types...
bojanz’s picture

Status: Reviewed & tested by the community » Fixed

Moved the logic to a helper method, since it's repeating.
Credit goes to dawehner for figuring out the correct logic.

Thanks, everyone.

EDIT: Forgot to squash. Oh, well.

Status: Fixed » Closed (fixed)

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

xandeadx’s picture

Again. If i create reference field to user (entity without bundles) and set widget "Inline Entity Form - Simple", when form render empty fieldset wihtout widget.