This is like a follow up of Required nested IEF forms don't work.
In that issue, there was a resolution for a nested IEF when there was a required IEF field and the page was submitted without clicking the confirmation button on the IEF form.
Though in the previous field the solution worked, it did not fix the issue for the existing entities.
I am returning with the same issue but for a different button.
Steps to reproduce:
- Enable IEF
- Create two content types A and B
- On entity A, create a entity reference field referencing to content type B and mark it as required
- Set the form view for the reference field in content type A to be a complex IEF form that allowes to add new entities
- Create an entity of type B
- Go to the node/add page for entity type A
- Fill in the title as it is required
- In the IEF form press "Add existing"
- Select the existing entity of content type B
- Do NOT press the "Add " confirmation button in the IEF form
- Submit the parent form
- Expected behavior: The entity is saved with the reference
- Actual result:Submission fails with message 'This value should not be null'
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | 2830328-required-ief-existing-entity-reroll-2.patch | 9.17 KB | kaythay |
Comments
Comment #2
dimilias commentedThis is only the failing test.
Comment #3
claudiu.cristeaLet's trigger the test.
Comment #5
dimilias commentedI have created a small patch which is a first approach that seem to fix the problem though I haven't tested it in nested forms and the failing test above is also not for a nested case.
I found out that after the ticket that I refer at the top, there was a @todo added referring to the unimplemented part of the existing entities.
For this part, I used a simplified version of the Drupal\Core\Entity\Element\EntityAutocomplete::validateEntityAutocomplete static method and the Drupal\Core\Entity\Element\EntityAutocomplete::matchEntityByTitle protected static method which are used for the normal autocomplete field.
It seems to solve the issue though I might have missed something. And I have tried it for both selecting from autocomplete and for selecting by label.
The label does is not included in the test but other tests were failing when it was not ready.
Comment #6
dimilias commentedComment #7
dimilias commentedUpdate: I haven't written a test for this but in a manual test I created 3 content types A, B, C.
The A has a reference to B and the B to C.
In the forms, A and B are using the IEF to refer to B and C respectively, both of which are mandatory fields.
There is an existing entity of C type.
I went to the create form of A and through the IEF I pressed create new entity (B).
In the nested IEF of B I pressed the "Add existing" button.
I filled in everything properly. Everything worked like charm :)
Comment #8
claudiu.cristeaAssigning for review.
Comment #9
sandervd commentedThanks @idimopoulos,
Works like a charm!
Comment #10
pfrenssenFound a couple of nits:
According to the coding standards,
elseifshould be written as one word. It is also a good practice to use===instead of==when doing string comparisons.Let's use the shorthand array syntax
[].This can be applied throughout the whole patch.
The first forward slash should be a backslash.
Let's inject this service rather than sideloading it.
Comment #11
alunyov commentedAdjusted code. Replaced loading the service statically with dependency injection. Please review it.
Comment #12
dunebl#11 is doing the job.
Many thanks alunyov!!
Comment #13
darvanenAs per #10.1 and Drupal coding standards, these need to be two words:
else if () {.Otherwise the patch works well, and should be RTBC when that last nit is fixed. Please remember to include an interdiff.
Comment #14
darvanenComment #15
alunyov commented@Darvanen,
I'm sorry, but I didn't get your point:
According to codding standards it should be elseif (like it is in code now). Even if you check link you are referencing Control Structures it says:
Getting the ticket back to RTBC.
Comment #16
darvanenWow, I totally had that backwards, sorry.
It wasn't RTBC when I commented but I agree it is now.
Comment #17
duneblI think the patch needs to be rerolled:
Comment #18
darvanenQueued for re-testing against 8.6
Comment #20
kaythay commentedJust needed a minor modification to get it working. Please review!
Comment #22
darvanenThanks @kathay, can we have an interdiff next time please?
Looks like it's failing, but at least it's applying!
Comment #23
kaythay commentedLooks like a test function was replaced between #11 and #20. Updated the patch with interdiff against #1.
Comment #24
kaythay commentedComment #25
darvanenSorry @kaythay the interdiff we need is against #11 - the most recently reviewed patch. I'm struggling to find the difference between that and your patches except for the line numbers.
Comment #26
kaythay commentedSorry about that. #11 was actually not a full patch and only applied against #2 so I had only interdiffed against #2. Here is the interdiff against #11.
Comment #27
darvanenI think perhaps that hunk didn't apply when you went to create the interdiff because both patches contain that section.
What I'm taking from this is that your reroll of the patch didn't change any code, just the line numbers in the patches (which was necessary, obviously because #11 wasn't applying properly.
Is that correct? If you didn't change any code, this is RTBC.
Comment #28
kaythay commentedThe only change besides line number was changing
$this->setAllowExisting(TRUE);to$this->updateSetting('allow_existing', TRUE);in #23 for tests to pass.Comment #29
darvanenGreat! Then I call #23 RTBC based on previous reviews.
Comment #30
andrey.troeglazov commentedHello,
The #23 patch applied correctly and working as expected.
+1 for RTBC.
Tested on dev branch.
Comment #31
andrey.troeglazov commentedComment #32
jonathanshawComment #33
jonathanshawComment #34
knyshuk.vova commented+1 to RTBC
Comment #36
kaythay commentedThanks, everyone.
Comment #38
mattltHello,
Just updated from rc1 to rc2 and our inline_entity_form for existing entities started not working. Reverting back to rc1 got everything working again.
In rc2 when trying to select an existing image I would get the following error…
Notice: Undefined index: entity_id in Drupal\inline_entity_form\Plugin\Field\FieldWidget\InlineEntityFormComplex->extractFormValues() (line 621 of /modules/contrib/inline_entity_form/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php).Please let me know if you need more information.
Thanks,
•• matt