Needs work
Project:
Inline Entity Form
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
8 Apr 2016 at 04:48 UTC
Updated:
19 Sep 2023 at 00:58 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
bojanz commentedYou can't, there's no integration for users. Someone will need to create an inline form handler for users.
Comment #3
eugene.ilyin commentedI can help. I have tried to do it myself but I'm stuck. Maybe you can give me few advice how to start?
Comment #4
eugene.ilyin commentedI have implemented integration for user entity type. It's pretty hacky, but I'm restricted in time and I don't see better way.
In any case it works and it helps me.
Maybe it will be useful for somebody.
Comment #5
hydra commentedThx for sharing, this is indeed working!
The code doesn't look bad, but since I'm not (yet) into inline_entity_form I wont't RTBC it. But perhaps a more experienced developer will have a look at it when seeing that this patch is functional.
Comment #6
eugene.ilyin commentedI have found that password cannot be saved through user entity inline form due the some features of processing of this field.
I have prepared new patch, which solves this problem.
Comment #7
eugene.ilyin commentedCould somebody review my patch?
Comment #8
init90Hello:)
I am testing the path, but it does not work on drupal 8.1.3.
Comment #9
eugene.ilyin commented@DovganPavlo, could you explain please, what the problem?
Comment #10
init90The button 'Create user' does not work. Error message after material saving:
Fatal error: Cannot create references to/from string offsets nor overloaded objects in /var/www/icareix-web/docroot/core/lib/Drupal/Component/Utility/NestedArray.php on line 155
Comment #11
sokru commentedIt works, but I hope it gets code review before RTBC.
Comment #12
betoquiroga commentedI have the same error than DovganPavlo - #10 - on Drupal 8.1.6
If I fill only the username and password fields, the user is created, but columns are NULL on the database
Comment #13
dawehnerI'm wondering whether we could add some little test about this small bit of the functionality?
Comment #14
grimreaperHello,
Thank you very much for the patch.
I just have tested the patch from comment 6 and it works.
But I was not abled to apply the patch using composer. I have inline_entity_form added with Drupal commerce 2.0.0-beta3.
In my use case I will also have to do some alter on the core permissions.
I want to use inline entity form to make a ticketing system where you can buy a ticket for another user. Unfortunately to be able to create a user, the 'administer users' permission is needed which is too much.
When I will have time, I will try to help with the tests to have this feature merged before making the alter for my project.
Comment #15
grimreaperHello,
Here is the patch from comment 6 rebased to the last code base.
Before writing test, I found a bug.
Creating the user is OK, but editing this user using inline_entity_form does not work.
It loads the same form for the user creation, an empty form, the user's values are not used.
I will try to remove this bug before writing tests.
EDIT: Also user creation does not work using 'Inline entity form - simple' widget: I got the error "Password field is required." whereas I filled it.
Comment #16
eugene.ilyin commentedHello
I've prepared a new patch. It's not ideal and supports only widget "Entity Inline Form - complex". Due the investigation I found that seems there is no good way to implement support of the User entity. The main reason is that some fields of user entity, like name or mail, cannot be loaded as usual fields in EntityFormDisplay->collectRenderDisplay(). They are defined manually in AccountForm.
I've tested this patch with Drupal 8.2
But this functionality is very critical for my project and maybe somebody else will find it useful.
Any reviews are welcome.
Comment #17
grimreaperHello,
Thanks eugene.ilyin for the patch.
Ok to focus on the "Entity Inline Form - complex" widget.
Here are my manual testing scenarios, as an administrator:
- creation of a user : OK
- edit of a user : OK (It works now thanks)
- start filling a user, reload the page with "f5" : KO, inline entity form does not load the right form.
- save a user form with error like a required field : KO, no error highlighted and then inline entity form is broken, it does not load the right form.
Comment #18
grimreaperHere is a patch to add some config for automated testing.
2 content types:
- one for multi value field on user reference with complex widget
- one for single value user reference with simple widget
I also note that some other test config have uuid in the config files. Should I make a patch in another issue to remove its?
Comment #20
grimreaperRemoving a path field that adds a dependency on the path module.
Comment #21
grimreaperHere is a beginning of tests for user integration. Currently it only checks if fields are here.
There are two patches:
- one with the test and the config only which should fail
- one with the test and the config and the patch from eugene.ilyin should be ok.
I added a text field on the user entity.
Comment #23
grimreaperHere is a patch with another test that checks user creation and edition.
Note that the check in case of form error is commented as it does not work yet.
Comment #24
dmsmidtGreat work so far!
I manually tested using a different form view mode in which I hid "fields" like "Timezone". However they are still displayed in the IEF.
Also as mentioned in #17, validation is broken.
And it seems that the values of all non-fieldapi fields are stored in a wrong structure in $form_state['values'].
For example 'roles' are in ' $form_state->values['roles']' but they should reside in: '$form_state->values['field_your_user_reference_field']['form']['inline_entity_form']['entities'][0]['form']['roles']'.
The following logic results in wrong '#array_parents' and '#parents' for all elements and child elements.
Comment #25
nebel54It looks like
got accidently into the if statement for the contact module here. It should be after it, to get the cleanup done.
Comment #26
dpiComment #27
grimreaperHello,
Thanks @Nebel54 for seing that. I changed that in the patch.
@dmsmidt: thanks for testing. For me when I remove the timezone field it works, I don't see it anymore in inline entity form.
Thanks for pointing the problem of #parents, #array_parents. I tried to analyze the target structure but I didn't managed to get it working and the form is still not reloaded in case of error, the ajax simply fails.
Comment #28
brayfe commentedThanks for the awesome module and the work on the patch! The patch in #27 does exactly what I need it to (allows an admin to create a new user with custom fields while filling out an order for that user). There is a small problem I found, but it won't prevent me from using the patched module. I had created some custom field logic using the State API within a hook_form_alter for the 'user_form', however, the custom code states aren't reflected when I load the form using this module. It also isn't running the custom validate code for the same form. Please let me know if I can help provide more context or code to help resolve this issue.
Comment #29
rezk2ll commentedhow can i install this patch on 7 ?
Comment #30
robpowell@grimreaper curious, why not use array_map for this use case?
My thoughts are that's what array_map is made to do.
I can't tell if this is the validation bug brought up earlier but I cannot save the node my user inline_entity_form is on
Really excited about this functionality, it would be great to get this ticket in before the 1 year anny. :D
Comment #31
rakesh.gectcrIs it possible for us to roll this quickly
We have a dependent for this
https://www.drupal.org/project/commerce_pos/issues/2921655#comment-12415488
Comment #32
rakesh.gectcrThank you everyone,
Amazing work so far, I am having a humble request while applying patch Kindly add the interdiff file, so that others who is looking to review or to work, life will be easy.... :)
Comment #33
kolin commentedThis will now respect any hook_form_user_register_form implementations.
Comment #34
kolin commentedComment #35
dylan donkersgoed commentedI'm having the same issue as robpowell in #30. It looks like the fields in the account subform are being wiped out and the password field specifically complains about validation errors.
Comment #36
dylan donkersgoed commentedNot quite there yet but I think this is an improvement. It does it in a bit of a convoluted way but this patch gets both the entity fields and the form fields and successfully saves the entity for the simple widget. Unfortunately it isn't actually saving the *reference* to the entity properly yet.
Comment #37
kolin commentedI've just tried out #36
Previously with #33 Clicking "Create User" in the inline form would create the user correctly and replace the inline form with the correct preview of the user. But validation didn't work.
With #36 this seems to be the opposite. Validation works but the form doesn't change.
I'll have another look at this tonight and see if I can figure out how to get both working.
Comment #38
attisanany progress on this?
Comment #39
asherry commentedThis helps me out immensely, thank you all so much for you work!
Two issues I'm having with it:
- I'm not sure why the alter for form_user_register_form is being invoked manually, I would imagine that would automatically be called if you set the #form_mode to 'register'. In my case it's creating a weird loop, because I'm trying to embed the user form on a profile module entity form. With form_user_register_form_alter being called, the profile module is then automatically attaching an inline form to the existing inline form.
- I'm trying to get this working with just a form element, and it seems like in the copyFormValuesToEntity function there is:
If I set my element to #tree => TRUE, then the $account_values is properly populated, but $field_values is not. If it is #tree => FALSE, then the reverse. Am I missing something?
Here is my element so far:
Comment #40
cjsmith87 commentedAny progress on this? I really need this feature for my production site
Comment #41
netw3rker commentedIt looks like the primary issue here is that the username, pass, mail, and other fields are not widget based fields that are defined in the entity field properties. Worse, these two types of definitions are created in two different types of forms (form objects from a controller, and classic form arrays). This patch makes a good attempt at bringing the fields from one to the other, but they just aren't designed to do that, and issues like validation are not preserved.
It occurred to me that this would be solved if there were a patch to core that provided these fields as proper entity fields. If that exists then the native entity handling for IEF would work just fine without the need for this patch.
After some digging, i found: https://www.drupal.org/project/drupal/issues/2227381 which applies formatters and widgets to those fields.
Once I applied that patch, I did not need the patch in this issue, and the user fields appear, and validate as expected.
Hope this helps!
Comment #42
geek-merlinIt looks like this patch contains a lot of unrelated changes that may or may not make sense, but prevent an effective review.
Comment #43
philltran commentedRe-rolled the #27 patch against latest dev branch.
While the now user saves with roles, we need to add logic to save user status and language.
Changing
$entity = $entity_form['#entity'];to$entity = \Drupal\user\Entity\User::create();and using 'register' form display ($form = \Drupal::service('entity.form_builder')->getForm($entity, 'register');) makes the username and password field appear. Previously, the username field was set with type of hidden causing the field to be ... uh hidden.Comment #44
philltran commentedComment #45
yassersammanTested #44
The fields do appear. but still having issues with the password field.
Submitting the form clears Roles, Email, Username and Password fields along side the password validation failure. it seems that values aren't reaching the parent class properly.
The error is raised in
EntityInlineForminside
entityFormValidate, when callingform_display->validateFormValues($entity, $entity_form, $form_state);Comment #46
cjsmith87 commentedComing back to this 2 years later, is there any progress on this issue? It is a great module but really need to be able to use it with users
Comment #47
spleshkaI started from the ideas defined in #36, but as it usually happens ended up rewriting it all :) The most notable difference between #36 and my patch is that I use standard buildEntity() method from in \Drupal\user\RegisterForm to populate user entity fields. It covers more use cases than #36. What the patch still does not do is executing RegisterForm::submitForm and RegisterForm::save (which handles things like sending email notifications, etc), because it was outside of the scope for my use case (I use Entity Browser to handle the form). I believe that if someone will have a use case for user creation flow with Inline Entity Form only then adding those submit handles should be pretty straight forward.
I'm not changing the status of the issue because the work is still needed to provide full integration with Inline Entity Form, but hopefully it'll be a good reference for someone else to complete the task.
Comment #48
lalop commentedI've an issue with patch from #47 when using an other form mode then the default one.
Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException: The "user" entity type did not specify a "inline_form" form class. in Drupal\Core\Entity\EntityTypeManager->getFormObject() (line 211 of core/lib/Drupal/Core/Entity/EntityTypeManager.php).Comment #49
afagioliFeedback on patch #47
On submit:
Comment #50
jigariusWhile trying the patch in #47, I get the following issues:
* UserInlineForm should use
EntityInterface $entityinstead ofContentEntityInterfaceto be compatible with the parent class.* The inline form works in the "default" form mode but it doesn't work with custom form modes that I've created, say "membership". I get the following error:
* Say, you hide the "timezone" field from the registration form. The inline entity form still shows this field even though the form mode is set to "register" correctly.
One more thing to keep in mind is whether the form alter hooks are triggered correctly for the user form. Say, if you're using a module to hide the username field, is that module being able to affect the registration form correctly. Example: auto_username or remove_username
Comment #52
jigariusI took a look at the patch 47 and created a PR with some changes. In the end, I got the user creation to work, but for some reason, the newly generated user's ID doesn't get attached to the parent entity's form correctly, i.e. the inline_entity_form elements are not replaced by a nice target_id so the parent form fails to submit.
In patch 47, the "account" element for the user data don't get copied into the User entity because the AccountForm expects a different structure of values in the FormState. I'm starting to think that it might be better to create a simplified version of the user account form for use with the InlineEntityForm instead of involving AccountForm at all.
As for my project, I'll be simplifying this by injecting just: name, mail, pass, status, and the Field API fields, if any. At least it will get the ball rolling for me.