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

christian.wiedemann’s picture

StatusFileSize
new10 KB
bojanz’s picture

Title: UserInlineEntityFormController include user_category (Profile2) support » Provide "user" entity type integration
Category: support » feature
Status: Active » Needs review
paulmicha’s picture

After 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"


  /**
   * Returns an array of fields (which can be either Field API fields or
   * properties defined through hook_entity_property_info()) that should be
   * used to represent a selected entity in the IEF table.
   *
   * The IEF widget can have its own fields specified in the widget settings,
   * in which case the output of this function is ignored.
   *
   * @param $bundles
   *   An array of allowed $bundles for this widget.
   *
   * @return
   *   An array of field information, keyed by field name. Allowed keys:
   *   - type: 'field' or 'property',
   *   - label: Human readable name of the field, shown to the user.
   *   - weight: The position of the field relative to other fields.
   *   - visible: Whether the field should be displayed.
   *   Special keys for type 'field':
   *   - formatter: The formatter used to display the field, or "hidden".
   *   - settings: An array passed to the formatter. If empty, defaults are used.
   *   - delta: If provided, limits the field to just the specified delta.
   */
  public function defaultFields($bundles) {
    $info = entity_get_info($this->entityType);
    $metadata = entity_get_property_info($this->entityType);
    $fields = array();
    $label_key = 'name';
    $fields[$label_key] = array(
      'type' => 'property',
      'label' => $metadata ? $metadata['properties'][$label_key]['label'] : t('Label'),
      'visible' => TRUE,
      'weight' => 1,
    );
    if (count($bundles) > 1) {
      $bundle_key = $info['entity keys']['bundle'];
      $fields[$bundle_key] = array(
        'type' => 'property',
        'label' => $metadata ? $metadata['properties'][$bundle_key]['label'] : t('Type'),
        'visible' => TRUE,
        'weight' => 2,
      );
    }

    return $fields;
  }
mile23’s picture

StatusFileSize
new4.75 KB

Here'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. :-)

barthje’s picture

There 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:

private function getFormState($form_state,$entity_form) { 
  	$child_form_state = form_state_defaults();
  	$child_form_state['values'] = drupal_array_get_nested_value($form_state['values'], $entity_form['#parents']);
	//$child_form_state['values'] = array_merge($child_form_state['values'], $child_form_state['values']['account']);

        // The account values are in to deep.
  	$child_form_state['values'] += $child_form_state['values']['account'];
  	return $child_form_state;
  }

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:

public function entityFormSubmit(&$entity_form, &$form_state) {
    parent::entityFormSubmit($entity_form, $form_state);
    $child_form_state = $this->getFormState($form_state,$entity_form);
    $account = $entity_form['#entity'];
    
    if (isset($account->uid) && $account->uid!=0) {
    	require_once drupal_get_path('module', 'user').'/user.pages.inc';
    	$child_form_state['user']=$account;
    	//$entity_form['#user_category']='main';
    	
    	user_profile_form_submit($entity_form, $child_form_state);
		    	
    }else { 
    	user_register_submit($entity_form, $child_form_state);
    	$entity_form['#entity'] = $child_form_state['user'];
    }
  }
barthje’s picture

I'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.

lklimek’s picture

@barthje did you manage to make any progress with this?

codium’s picture

Issue summary: View changes
StatusFileSize
new4.64 KB

Made 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.

user654’s picture

.

lklimek’s picture

#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 :-).

codium’s picture

StatusFileSize
new6.43 KB

Please test this patch

user654’s picture

.

user654’s picture

.

codium’s picture

@pinkonomy do you getting some PHP warnings when using user entity with ief? If yes could you paste them here?

codium’s picture

Assigned: Unassigned » codium
robcarr’s picture

I'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

user654’s picture

.

robcarr’s picture

In 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.

lklimek’s picture

Try attached patches. I didn't test it on -dev - just re-rolled it.

robcarr’s picture

Thanks @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...

lklimek’s picture

@arrrgh what are these conflicts? I use LoginToboggan, too, but without Profile2 - and it works. So probably this is a conflict with Profile2?

codium’s picture

When 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?

  /**
   * Overrides EntityInlineEntityFormController::save()
   */
  public function save($entity, $context) {
    if (! isset($entity->uid)) {
      entity_save($this->entityType, $entity);
    }
  }
codium’s picture

Version: 7.x-1.x-dev » 7.x-1.3
StatusFileSize
new5.92 KB

Added support for custom submit handler

absoludo’s picture

#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.inc

Also 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?

absoludo’s picture

I also noticed the form submit returned uid 0 instead of the newly created user.
I modified entityFormSubmit to

    if ($account->uid === FALSE || $account->uid == 0) {
codium’s picture

I've got feedback with validation issue when trying to edit, and create another user at the same time.

I added:

if ($entity_form['#title'] == t('Add new user')) {
      return;
}

before user validation code inside entityFormValidate method

codium’s picture

@absoludo if it works ok you are right with: $this->settings['allow_existing'] = 0;. It's artifact from my business logic.

dobrzyns’s picture

I'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:

  1. Create user
  2. Edit user
  3. Create user and edit user at same time

All scenarios included custom fields.

Please also test this.

dobrzyns’s picture

Version: 7.x-1.3 » 7.x-1.x-dev
pixelsweatshop’s picture

Status: Needs review » Needs work
StatusFileSize
new15.34 KB

Tested 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)

derekw’s picture

Also 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.

emattias’s picture

Status: Needs work » Needs review
StatusFileSize
new5.9 KB

Here'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.

emattias’s picture

Ignore the last patch. It includes changes from a different patch. Here's the patch that I talked about in #32

emattias’s picture

Here'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.

derekw’s picture

With #34 applied, when submitting the embedded new user form I get a long list of errors:

Notice: Undefined property: stdClass::$original in user_save() (line 510 of /home/tlskunk/public_html/modules/user/user.module).
Notice: Trying to get property of non-object in user_save() (line 510 of /home/tlskunk/public_html/modules/user/user.module).
Notice: Undefined property: stdClass::$original in user_save() (line 522 of /home/tlskunk/public_html/modules/user/user.module).
Notice: Trying to get property of non-object in user_save() (line 522 of /home/tlskunk/public_html/modules/user/user.module).
Notice: Undefined property: stdClass::$original in user_save() (line 540 of /home/tlskunk/public_html/modules/user/user.module).
Notice: Trying to get property of non-object in user_save() (line 540 of /home/tlskunk/public_html/modules/user/user.module).
Notice: Undefined property: stdClass::$original in user_save() (line 546 of /home/tlskunk/public_html/modules/user/user.module).
Notice: Trying to get property of non-object in user_save() (line 546 of /home/tlskunk/public_html/modules/user/user.module).
Notice: Undefined property: stdClass::$original in user_save() (line 557 of /home/tlskunk/public_html/modules/user/user.module).
Notice: Trying to get property of non-object in user_save() (line 557 of /home/tlskunk/public_html/modules/user/user.module).
Notice: Undefined property: stdClass::$login in user_pass_reset_url() (line 2338 of /home/tlskunk/public_html/modules/user/user.module).
Notice: Undefined property: stdClass::$login in user_cancel_url() (line 2360 of /home/tlskunk/public_html/modules/user/user.module).
Notice: Undefined property: stdClass::$login in user_pass_reset_url() (line 2338 of /home/tlskunk/public_html/modules/user/user.module).
Notice: Undefined property: stdClass::$login in user_cancel_url() (line 2360 of /home/tlskunk/public_html/modules/user/user.module).
Notice: Undefined property: stdClass::$original in user_save() (line 565 of /home/tlskunk/public_html/modules/user/user.module).
Warning: First parameter must either be an object or the name of an existing class in user_save() (line 565 of /home/tlskunk/public_html/modules/user/user.module).
Notice: Undefined property: stdClass::$original in user_save() (line 565 of /home/tlskunk/public_html/modules/user/user.module).
Warning: First parameter must either be an object or the name of an existing class in user_save() (line 565 of /home/tlskunk/public_html/modules/user/user.module).
Notice: Undefined property: stdClass::$original in user_save() (line 565 of /home/tlskunk/public_html/modules/user/user.module).
Warning: First parameter must either be an object or the name of an existing class in user_save() (line 565 of /home/tlskunk/public_html/modules/user/user.module).
Notice: Undefined property: stdClass::$original in user_save() (line 565 of /home/tlskunk/public_html/modules/user/user.module).
Warning: First parameter must either be an object or the name of an existing class in user_save() (line 565 of /home/tlskunk/public_html/modules/user/user.module).
Notice: Undefined property: stdClass::$original in user_save() (line 565 of /home/tlskunk/public_html/modules/user/user.module).
Warning: First parameter must either be an object or the name of an existing class in user_save() (line 565 of /home/tlskunk/public_html/modules/user/user.module).
Notice: Undefined property: stdClass::$original in user_save() (line 565 of /home/tlskunk/public_html/modules/user/user.module).
Warning: First parameter must either be an object or the name of an existing class in user_save() (line 565 of /home/tlskunk/public_html/modules/user/user.module).
Notice: Undefined property: stdClass::$original in user_save() (line 565 of /home/tlskunk/public_html/modules/user/user.module).
Warning: First parameter must either be an object or the name of an existing class in user_save() (line 565 of /home/tlskunk/public_html/modules/user/user.module).
Notice: Undefined property: stdClass::$original in user_save() (line 565 of /home/tlskunk/public_html/modules/user/user.module).
Warning: First parameter must either be an object or the name of an existing class in user_save() (line 565 of /home/tlskunk/public_html/modules/user/user.module).
Notice: Undefined property: stdClass::$original in user_save() (line 565 of /home/tlskunk/public_html/modules/user/user.module).
Warning: First parameter must either be an object or the name of an existing class in user_save() (line 565 of /home/tlskunk/public_html/modules/user/user.module).
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'field_user_account_target_id' cannot be null: INSERT INTO {field_data_field_user_account} (entity_type, entity_id, revision_id, bundle, delta, language, field_user_account_target_id) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6); Array ( [:db_insert_placeholder_0] => node [:db_insert_placeholder_1] => 1010 [:db_insert_placeholder_2] => 1010 [:db_insert_placeholder_3] => contact [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => ) in field_sql_storage_field_storage_write() (line 494 of /home/tlskunk/public_html/modules/field/modules/field_sql_storage/field_sql_storage.module).
PiTRiS’s picture

Tested 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)

Paul B’s picture

Assigned: codium » Unassigned
Status: Needs review » Needs work

I 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.

ecrown’s picture

i tried applying the patch at #34 against the latest dev version and the patch fails on .info file

patching file includes/user.inline_entity_form.inc
patching file inline_entity_form.info
Hunk #1 FAILED at 10.
1 out of 1 hunk FAILED -- saving rejects to file inline_entity_form.info.rej
patching file inline_entity_form.module
Hunk #2 succeeded at 1300 with fuzz 2 (offset -5 lines).
Hunk #3 succeeded at 1647 (offset 66 lines).

But the patch at #28 works fine for me against 7.x-1.5

noahott’s picture

I 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?

totolearn’s picture

subscribed

netw3rker’s picture

netw3rker’s picture

StatusFileSize
new6.12 KB

After 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!

netw3rker’s picture

StatusFileSize
new6.34 KB

Here'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.

bernardopaulino’s picture

patch #42 worked for me thanks.

ph7’s picture

Why isn't patch #42 committed into code? It's been 9 months...

jpdaut’s picture

With #43 I see the user as "Anonymous". The UserInlineEntityFormController save() function is never called. So the user entity is not saved.

bluegeek9’s picture

Status: Needs work » Closed (outdated)

We appreciate your contributions to Inline Entity Form. Drupal 7 in End-of-Life. We encourage you to upgrade to a supported version of Drupal.

//www.flaticon.com/free-icons/thank-you Thank you for your contribution! Your continued support makes this project sustainable.
There are multiple ways to show appreciation for the work contributed to this project including:

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.