While we already ported multivalue field widget we still need to do single value one.

Comments

slashrsm’s picture

Status: Active » Needs review
Related issues: +#2491527: [Drupal8] IEF FieldWidget merge & refactor
StatusFileSize
new25.14 KB

Initial implementation attached. It is based of #2491527-13: [Drupal8] IEF FieldWidget merge & refactor. Patch from that issue needs to be applied in order to test this patch.

There are two known issues:

  1. Attempt to save will fail if using IEF single widget on a reuired field. Inline entity if build on submit, which happens after validation step. As a result of that we don't have IEF entity at the moment of validation, which obviously causes problems. Still need to figure out how to fix this. Any sugguestions are welcome.
  2. Trying to edit/create an inline entity of the same type as parent entity will result in very strange issues. Main reason for them is static caching of entity form display entities in Drupal core. The best was to fix IMO is to make entity form display type configurable (we currently hard-code "default" type) as issues only appear if one uses same entity type and same entity form display type.

Status: Needs review » Needs work

The last submitted patch, 1: 2508107_1.patch, failed testing.

webflo’s picture

Needs re-roll because i committed the schema from #2481919-9: Adds schema for inline_entity_form.

floretan’s picture

Status: Needs work » Needs review
StatusFileSize
new25.14 KB

Here's a re-rolled patch. Note that this patch depends on the patch from comment #16 #2491527: [Drupal8] IEF FieldWidget merge & refactor.

I was able to use it without any noticeable side-effects.

Status: Needs review » Needs work

The last submitted patch, 4: 2508107-4-single-ief.patch, failed testing.

floretan’s picture

I was able to use it without any noticeable side-effects. Sorry, spoke too soon.

There's an error due to undefined method updateRowWeights() on InlineEntityFormMultiple when using a multiple-valued widget within a single-valued widget (a gallery with images for example). The validation handler "inline_entity_form_required_field" is also missing.

slashrsm’s picture

Status: Needs work » Needs review

This was actually caused by the refactor patch. See #2491527-17: [Drupal8] IEF FieldWidget merge & refactor for fix.

Thank you for testing!

slashrsm’s picture

Status: Needs review » Needs work

Quoting @floretan (originally posted in #2491527-18: [Drupal8] IEF FieldWidget merge & refactor:

I have an article node type with an optional entity reference field pointing to a gallery (media_entity) which has a required entity reference field pointing to images (different bundle of media_entity). Everything works when I use a multiple IEF for both, but I get these issues when using the single IEF for the field attached to the article node type.

- Create an article without any images in the gallery. I realize that the expected behavior is not fully clear (should no entity get saved, or should we throw an error). What we get is a fatal error combined with a user error that the field is required.
- Create an article with one image in the gallery and save it. Then open the edit form and save again without any changes. Then media_entity throws an error "The media on this page has either been modified by another user, or you have already submitted modifications using this form. As a result, your changes cannot be saved. ". I haven't investigated yet if this is an issue with media_entity or with this patch, but it's the interaction between the two that causes problems

slashrsm’s picture

Create an article without any images in the gallery. I realize that the expected behavior is not fully clear (should no entity get saved, or should we throw an error). What we get is a fatal error combined with a user error that the field is required.

I _think_ that I noticed a comment somewhere in the codebase that basically says "we assume required field for single widget". This is also how D7 version works. As soon as there are required fields on inline entity (which is 99% of cases I guess) validation forces you to fill them in. We can either keep this behaviour in D8 or allow non-required reference fields to use this widget. In the latter case we'd also need to re-think the workflow part.

slashrsm’s picture

- Create an article with one image in the gallery and save it. Then open the edit form and save again without any changes. Then media_entity throws an error "The media on this page has either been modified by another user, or you have already submitted modifications using this form. As a result, your changes cannot be saved. ". I haven't investigated yet if this is an issue with media_entity or with this patch, but it's the interaction between the two that causes problems

I tried to reproduce this. My setup:
- D8 latest cehckout
- IEF, media_entity, media_entity_image and media_entity_slideshow (all latest checkout)
- configured my content type and media bundles similar to how you did it (node -> "slideshow" media bundle -> "image" media bundle)
- slideshow field uses single IEF widget
- image field uses multiple IEF widget

I tried many different execution paths (create node with image slideshow, edit it with no changes, edit it with changes, save with image IEF left open, save with image IEF closed and saved) and was unable to reproduce error you mentioned. Could you try to get some more context? Maybe by putting a breakpoint at the line of error message and seeing where exactly this happens (on which media entity, ...).

slashrsm’s picture

Issue tags: +Media Initiative, +sprint
floretan’s picture

Thank you, I'll do some more testing to identify these edge cases more precisely.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: 2508107-4-single-ief.patch, failed testing.

Status: Needs work » Needs review

isntall queued 4: 2508107-4-single-ief.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 4: 2508107-4-single-ief.patch, failed testing.

slashrsm’s picture

Issue tags: -sprint +D8Media
slashrsm’s picture

Status: Needs work » Needs review
StatusFileSize
new25.14 KB

Reroll.

slashrsm’s picture

Related issues: +#2532810: Decide on final widget UX
StatusFileSize
new28.24 KB
new6.66 KB

Few more things added:
- renamed to "Simple" as discussed in #2532810: Decide on final widget UX
- widget is now correctly displayed even for multivalue fields
- validation is now correctly handled for required fields

There are still some problems when saving mutivalue field values. I suspect that this happens for the same reason as problem nr. 2 that I mentioned in #1.

slashrsm’s picture

StatusFileSize
new42.69 KB
new21.36 KB

Problem that I mentioned in #19 should be fixed now. I also started to work on tests but then noticed a problem that I described in #2510274-9: Add ability to select form Display Mode so I couldn't finish them.

slashrsm’s picture

StatusFileSize
new42.72 KB
new908 bytes

Another small fix.

woprrr’s picture

Issue summary: View changes
Status: Needs review » Needs work
StatusFileSize
new148.17 KB

@slashrsm I ve tried your last patch and I loose the single widget. The field is in cardinality 1.

slashrsm’s picture

Issue summary: View changes
Status: Needs work » Needs review
+++ b/src/Plugin/Field/FieldWidget/InlineEntityFormSimple.php
@@ -0,0 +1,164 @@
+  /**
+   * {@inheritdoc}
+   */
+  public static function isApplicable(FieldDefinitionInterface $field_definition) {
+    if (!$field_definition->isRequired()) {
+      return FALSE;
+    }
+
+    if (count($field_definition->getSettings()['handler_settings']['target_bundles']) != 1) {
+      return FALSE;
+    }
+
+    return TRUE;
+  }
+

Widget will only appear on required fields that target one bundle only. Please make sure you meet this requirements.

woprrr’s picture

StatusFileSize
new749.56 KB
new717.42 KB
new457.22 KB

After actually test it works well to use the simple widget. However I identify two other bugs.

1 / When you create a node A with the field that uses simple widget we have a second boolean "create a review" arrives duplicate of the parent entity see screenshot (IEF-001).

2 / When I created my content I normally submits the form, I have my entity created by IEF against my parent entity record is not see screen 2 and 3. Here are the VM to test the sample: https://dag2.ply.st/admin/content

woprrr’s picture

Status: Needs review » Needs work

slashrsm queued 21: 2508107_21.patch for re-testing.

The last submitted patch, 21: 2508107_21.patch, failed testing.

slashrsm’s picture

Status: Needs work » Needs review
StatusFileSize
new40.69 KB

Reroll.

Status: Needs review » Needs work

The last submitted patch, 28: 2508107_26.patch, failed testing.

slashrsm’s picture

Status: Needs work » Needs review
StatusFileSize
new41.09 KB
new650 bytes

  • slashrsm committed b25402c on 8.x-1.x
    Issue #2508107 by slashrsm, floretan: Port "Single" IEF field widget to...
slashrsm’s picture

Status: Needs review » Fixed

After discussing this with @bojanz on IRC I decided to commit it. Otherwise we could end in a reroll hell. Let's tackle remaining bugs in follow-up tickets.

@woprrr could you open bug reports about your findings?

Status: Fixed » Closed (fixed)

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