Comments

Peter Haight created an issue. See original summary.

skyredwang’s picture

Status: Needs review » Needs work
+++ b/src/Element/InlineEntityForm.php
index ea5102c..ff6fd9a 100644
--- a/src/Plugin/Field/FieldWidget/InlineEntityFormMultiple.php

This file has been renamed to InlineEntityFormComplex.php

+++ b/src/Plugin/Field/FieldWidget/InlineEntityFormMultiple.php
@@ -865,10 +865,8 @@ class InlineEntityFormMultiple extends InlineEntityFormBase implements Container
+    $widget = $form_display->getComponent($instance->getName());

This change seems to be only coding style change.

After the patching, the form still reports "You must enter a username.", even though the username has been entered.

eyal shalev’s picture

Title: Doesn't work for entities with no bundles. » Enable compatibility with bundle-less entities
Priority: Normal » Major
Issue summary: View changes
zviryatko’s picture

Updated patch accordingly to

This file has been renamed to InlineEntityFormComplex.php
tedbow’s picture

Status: Needs work » Needs review

Setting to needs review to run test. Pretty sure this will need to re-rolled though because of changes to module

tedbow’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Applied the patch but it doesn't fix it for me.

After the patching, the form still reports "You must enter a username.", even though the username has been entered.

Same for me

tedbow’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new9.7 KB

Ok here is TEST_ONLY patch for now. This fails of course now.

Will need to be re-written when we get this functionality working.

Status: Needs review » Needs work

The last submitted patch, 7: ief-create_user-2569193-7_TEST_ONLY.patch, failed testing.

tedbow’s picture

Status: Needs work » Needs review
StatusFileSize
new7.02 KB

argggh forgot undo function renames for local testing.

Will still fail.

Status: Needs review » Needs work

The last submitted patch, 9: ief-create_user-2569193-9_TEST_ONLY.patch, failed testing.

bojanz’s picture

I'm not sure user is the best entity type to use in a test, the AccountForm is almost completely custom, which means that as soon as we start using the form mode, this test will fail. Better use nodes.

tedbow’s picture

Better use nodes.

How can we test for entities without bundles if we are using nodes?

bojanz’s picture

Oh, right. Fun. Back to the drawing board.

yce’s picture

Looks like the first hunk is no longer needed, I've recreated the patch for the latest dev version.

jan.mashat’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 14: inline_entity_form-no-bundle-2569193-14.patch, failed testing.

yce’s picture

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

Status: Needs review » Needs work

The last submitted patch, 17: inline_entity_form-no-bundle-2569193-17.patch, failed testing.

boobaa’s picture

Manual tests say the patch solves the issue of the "Remove" button(s), so it looks like the automated tests need to be fixed.

bojanz’s picture

The tests are correct.

-    $widget = \Drupal::entityTypeManager()
-      ->getStorage('entity_form_display')
-      ->load($instance->getTargetEntityTypeId() . '.' . $instance->getTargetBundle() . '.default')
-      ->getComponent($instance->getName());
+    $form_display = entity_get_form_display($entity->getEntityTypeId(), $entity->bundle(), 'default');
+    $widget = $form_display->getComponent($instance->getName());

The previous code was loading the form display for the parent entity.
The new code loads the form display for the inline entity.
Hence the settings don't get loaded and the entity doesn't get removed from the system.

bojanz’s picture

Title: Enable compatibility with bundle-less entities » The simple widget doesn't support bundle-less entities
Status: Needs work » Active

Committed a more correct fix:
https://github.com/bojanz/inline_entity_form/commit/274143d6748b8aaa02eb...

What remains now is to make the Simple widget support bundle-less entities, by removing the condition from InlineEntityFormSimple::isApplicable(), and to commit Ted's test.

dawehner’s picture

Status: Active » Needs work
StatusFileSize
new2.55 KB

I'm using this hack for now, this missing tests though for example.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new11.65 KB
new8.02 KB

For a second I though, sure let's just apply the test from tedbow, together with my fix, done.

As it turns out after quite some debugging, using the user as test entity doesn't really make sense anymore, because we switched away from using the entity from, but rather have our own inline form.

This patch adds now test coverage using its own special entity type without bundle support.

dawehner’s picture

I tried to make a critical self review ... wasn't that easy :)

+++ b/src/Plugin/Field/FieldWidget/InlineEntityFormSimple.php
@@ -177,11 +177,12 @@ class InlineEntityFormSimple extends InlineEntityFormBase {
+    $handler_settings = $field_definition->getSettings()['handler_settings'];
+    $reference_entity_type_id = $field_definition->getFieldStorageDefinition()->getSetting('target_type');
+    if (!\Drupal::entityTypeManager()->getDefinition($reference_entity_type_id)->getBundleEntityType()) {
+      return TRUE;

This would be nice to have a quick comment.

benjy’s picture

Status: Needs review » Reviewed & tested by the community

This patch worked well for me. Thanks dawehner.

The last submitted patch, 22: 2569193-22.patch, failed testing.

bojanz’s picture

   public static function isApplicable(FieldDefinitionInterface $field_definition) {
-    if (!$field_definition->isRequired()) {
-      return FALSE;
+    $handler_settings = $field_definition->getSettings()['handler_settings'];
+    $reference_entity_type_id = $field_definition->getFieldStorageDefinition()->getSetting('target_type');
+    if (!\Drupal::entityTypeManager()->getDefinition($reference_entity_type_id)->getBundleEntityType()) {
+      return TRUE;
     }
 
-    $handler_settings = $field_definition->getSettings()['handler_settings'];
     // Entity types without bundles will throw notices on next condition so let's
     // stop before they do. We should support this kind of entities too. See
     // https://www.drupal.org/node/2569193 and remove this check once that issue

1) Don't we usually prefer "target" over "reference"? So $target_entity_type_id?
2) Let's assign \Drupal::entityTypeManager()->getDefinition($reference_entity_type_id) to a $target_entity_type, cleaner
3) Let's add a comment above return TRUE ("The target entity type doesn't use bundles, no need to validate them."?)
4) Wouldn't actually $target_entity_type->getKey('bundle') be more generic than checking for getBundleEntityType()?
5) The comment at the end is no longer relevant, we can delete it. In fact, we can reduce the entire bottom of the method to checking if count target bundles is 1, no?

dawehner’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new11.85 KB
new1.42 KB

Great review!

5) The comment at the end is no longer relevant, we can delete it. In fact, we can reduce the entire bottom of the method to checking if count target bundles is 1, no?

I fear that that target_bundles might not be set. Just having the count would result in a notice, see https://3v4l.org/lt6dR

bojanz’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, ship it!

  • dawehner committed 4d927e4 on 8.x-1.x
    Issue #2569193 by dawehner, tedbow, yce, Peter Haight, zviryatko: The...
dawehner’s picture

Status: Reviewed & tested by the community » Fixed

Thank you @bojanz!

Status: Fixed » Closed (fixed)

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