Hi,
i tried to implement an UserInlineEntityFormController. I attached it and it works so far. i can load an save users.
Two problems:
1. Valdiation works only for required fields. validation inside user_account_form_validate doesn't work. Even if i call them in entityFormValidate. the problem is inside form_set_error.
2. I want add additional "user_categories fields " added through profile2 while creating and updating an user. I figured out that form_alter is not triggered. The forms will be attached if i call form_alter on my own. But either saving nor validation is working.
The user_category should be added through field settings.
Hope you can give me some hints to solve the problems
Thanks for your great work and help
Christian
Comments
Comment #1
christian.wiedemann commentedComment #2
bojanz commentedComment #3
paulmicha commentedAfter testing with latest versions, Christian's module seems to work.
Titles of referenced users are uids though, so I added this method into his class "UserInlineEntityFormController"
Comment #4
mile23Here's #1 and #3 as a patch to inline_entity_form.
Problems:
For the single-entity form, validation always says that the email is missing.
For the multi-entity form, editing an existing user entity works, but trying to add another results in an AJAX error when you click 'submit.'
Also: Needs tests. :-)
Comment #5
barthje commentedThere are still a couple of bugs:
The biggest is in function getFormState. The account information is hidden in $child_form_state['values']['account']. The user_register and validate functions expect them to be in $child_form_state['values'].
A possible fix:
Another problem when creating a new user is that it doesn't have the saved entity in $entity_form['#entity']. See function entityFormSubmit.
A possible solution is:
Comment #6
barthje commentedI'm currently working on this code because we need to use it in our platform. I'll propose the patches/module here when it works as expected.
Comment #7
lklimek commented@barthje did you manage to make any progress with this?
Comment #8
codium commentedMade some changes in user entity controller. It seems to all work ok with basic user entity (crud + validation). Patch tested on stable and dev version.
Comment #9
user654 commented.
Comment #10
lklimek commented#8 on stable (1.3) version causes:
Fatal error: Class 'U' not found in inline_entity_form/inline_entity_form.module on line 103
Attached patch works with 1.3. Needs testing on -dev.
Remember to clear your cache :-).
Comment #11
codium commentedPlease test this patch
Comment #12
user654 commented.
Comment #13
user654 commented.
Comment #14
codium commented@pinkonomy do you getting some PHP warnings when using user entity with ief? If yes could you paste them here?
Comment #15
codium commentedComment #16
robcarrI'm a bit confused here - are we applying the patch against the IEF module, or the new module at #1876830-1: Provide "user" entity type integration ? The patch at #11 doesn't seem to apply against current DEV version of inline_entity_form
Comment #17
user654 commented.
Comment #18
robcarrIn that case I'm not getting the patch to apply. Error using both OSX Patch command and Git patch apply.
Using Git: Fails at line 10 of inline_entity_form.info
Using Patch: Sort of applies, but the folder is just a general mess
Checked folder permissions too, just in case.
I'll try a manual patch to see if that solves things.
Comment #19
lklimek commentedTry attached patches. I didn't test it on -dev - just re-rolled it.
Comment #20
robcarrThanks @lklimek
Patch applies now, and seems to work as planned (against DEV).
An aside really: I'm getting lots of conflicts with other modules (Profile2 and LoginToboggan seem to be the root). Think I'm asking too much of this module and the change proposed...
Comment #21
lklimek commented@arrrgh what are these conflicts? I use LoginToboggan, too, but without Profile2 - and it works. So probably this is a conflict with Profile2?
Comment #22
codium commentedWhen host node is saved, user entity is saved too, but with raw password in db table...This function should be added to user ief class IMO. Could some one test it?
Comment #23
codium commentedAdded support for custom submit handler
Comment #24
absoludo commented#23 helped me for 7.x-1.5, but I encountered some minor issues.
The patch did not include the newly created file which results in a fatal error:
files[] = includes/user.inline_entity_form.incAlso I did not understand at first why I could not set "Allow users to add existing users.".
So I removed
$this->settings['allow_existing'] = 0;from _construct() in the newly created user.inline_entity_form.inc file.Is there a reason why that line and the next line are overwriting the entity settings?
Comment #25
absoludo commentedI also noticed the form submit returned uid 0 instead of the newly created user.
I modified entityFormSubmit to
Comment #26
codium commentedI've got feedback with validation issue when trying to edit, and create another user at the same time.
I added:
before user validation code inside
entityFormValidatemethodComment #27
codium commented@absoludo if it works ok you are right with:
$this->settings['allow_existing'] = 0;. It's artifact from my business logic.Comment #28
dobrzyns commentedI've rolled a patch with the changes noted in #24 and #25. With these changes, I was not able to reproduce the issue in #26, and I was able to edit and create another user at the same time without issue.
I tested the following scenarios:
All scenarios included custom fields.
Please also test this.
Comment #29
dobrzyns commentedComment #30
pixelsweatshop commentedTested with latest dev and it appears when I click "create user" it tries to validate the required fields on the user entity even before I have had a chance to fill it in. Also the meta tags (when meta tags module is installed) show on the inline entity form when nothing has been entered yet. (See attached screenshot)
Comment #31
derekw commentedAlso on the validation front... if I use the Multi-Value Inline Entity Form widget, click Add User... there's no way to cancel it. The User form fields become required.
Comment #32
emattias commentedHere's the path from #28 but I removed the hardcoded disabling of allow existing setting and I made the cancel button work by not running user_account_form_validate() when canceling the form.
Comment #33
emattias commentedIgnore the last patch. It includes changes from a different patch. Here's the patch that I talked about in #32
Comment #34
emattias commentedHere's the same patch as #33 + this one also removes the hard coding of the execution of user_register_submit() in entityFormSubmit() resulting in it being run twice when creating a new user.
Comment #35
derekw commentedWith #34 applied, when submitting the embedded new user form I get a long list of errors:
Comment #36
PiTRiS commentedTested the latest patch with dev inline entity form and it does not work. After adding user, it's shown as anonymous and cannot be edited.
Also after saving the node with newly added referenced user entitites goes into error after saving (Site encountered an error with no extra info, not even in php log)
Comment #37
Paul B commentedI also see the user as "Anonymous" and the error after saving. In the error log it says
Column "entity_id" cannot be null
for one of the user fields.
Comment #38
ecrown commentedi tried applying the patch at #34 against the latest dev version and the patch fails on .info file
But the patch at #28 works fine for me against 7.x-1.5
Comment #39
noahott commentedI have patch at #34 working in that I can create new users through Inline Entity Form attached to a node. What I would like to do, which I am willing to pay for, is to be able to save Profile2 fields along with the user entity. Currently the profile2 fields are being show, but are never validated or saved to the database. Has anyone gotten this working or is willing to work on it?
Comment #40
totolearn commentedsubscribed
Comment #41
netw3rker commentedHere's a re-roll of #34 against 7.x-1.x
Comment #42
netw3rker commentedAfter applying the patch, I got the same errors as #35. It appears that the logic for whether to save a new user or update an existing one had been inverted. I corrected that, and then encountered a few other issues.
One problem with the userInlineEntityFormController class is that it is directly using the user_register form rather than using and setting up a form that works like the user_register form. (you can see an example of the difference when looking at the how it handles node forms). A consequence of this is that the form itself saves the user before the class can then correctly / properly save the user and track it with a field.
I went through and removed the two calls to functions that indirectly save the user - one is node_profile_save, and the other is the #submit handler of the form that specifically calls user_form_save. This then allows the user to be saved using $controller->save() the same way nodes are saved. After doing this, the target_id values are properly populated within the form and magic can begin to happen.
Hope this helps!
Comment #43
netw3rker commentedHere's another update to this. This was causing the user's password to be saved in cleartext, similar to what was reported in #22. This is a result of the entity_save() using entity_metadata_user_save which specifically unsets the password from the $edit variable, and specifically trusts the password in $account. since $entity in this case is a bunch of raw data, the unencrypted password is in there and gets saved as such. This new patch resolves that.
Comment #44
bernardopaulino commentedpatch #42 worked for me thanks.
Comment #45
ph7 commentedWhy isn't patch #42 committed into code? It's been 9 months...
Comment #46
jpdaut commentedWith #43 I see the user as "Anonymous". The UserInlineEntityFormController save() function is never called. So the user entity is not saved.
Comment #47
bluegeek9 commentedWe appreciate your contributions to Inline Entity Form. Drupal 7 in End-of-Life. We encourage you to upgrade to a supported version of Drupal.