entity_metadata_form_user() always builds the 'user_profile_form' form however this is only correct if we are requesting a user edit form. The user register form ('user_register_form') is potentially quite different and is needed when an anonymous user is registering.

I have rolled a patch that switches the form id depending on whether $account->uid is set.

Thanks

Josh

Comments

jeff h’s picture

Tested and working fine here.

Any maintainers got a few minutes to roll this patch in?

alexander allen’s picture

StatusFileSize
new1.67 KB

I created a manual test by calling drupal_get_form('user_register_form'); and entity_metadata_form_user($user); separately, and running a diff between the resulting form arrays.

The first big difference that I noticed is that when the profile2 module is enabled, it attaches it's own form api callbacks to the form's #validate and #submit parameters:

Example:
User Register form:

  '#user_category' => 'register',
 ...
  '#validate' => 
  array (
    0 => 'user_account_form_validate',
    1 => 'user_validate_picture',
    2 => 'user_register_validate',
    3 => 'profile2_form_validate_handler',
  ),
..
  '#submit' => 
  array (
    0 => 'metatag_metatags_form_submit',
    1 => 'user_register_submit',
    2 => 'profile2_form_submit_handler',
  ),

User Profile form:

  '#user_category' => 'account',
  '#validate' => 
  array (
    0 => 'user_account_form_validate',
    1 => 'user_validate_picture',
    2 => 'user_profile_form_validate',
  ),
...
  '#submit' => 
  array (
    0 => 'metatag_metatags_form_submit',
    1 => 'user_profile_form_submit',
  ),

The second big difference was that on the user register form, a profile2 entity got attached to the form under the profile_main key.

This means that integration with Entity API is broken for Profile2 users because they don't get profile entity fields attached to the anonymous user form - at least for this use case.

Example attached profile2 entity:

 'profile_main' => 
  array (
    '#tree' => true,
    '#parents' => 
    array (
      0 => 'profile_main',
    ),
    '#entity' => 
    Profile::__set_state(array(
       'pid' => NULL,
       'type' => 'main',
       'label' => 'Main profile',
       'uid' => NULL,
       'created' => NULL,
       'changed' => NULL,
       'entityType' => 'profile2',
       'entityInfo' => 
      array (
        'label' => 'Profile',
        'plural label' => 'Profiles',
        'description' => 'Profile2 user profiles.',
        'entity class' => 'Profile',
        'controller class' => 'EntityAPIController',
...

Other minor changes include:

- User profile form (user_profile_form) shows Time Zone options, registration form (user_register_form) does not.
- Form submit button on user_register_form reads: "Create new account".
- Form submit button on user_profile_form reads: "Save"

Based on this test, committing that patch would be at least beneficial for Profile2 users. But I can see how it's probably affecting any module that depends on the entity_metadata_form_user function.

I've attached a small file with an "informal" test case.

alexander allen’s picture

Priority: Critical » Major
Status: Active » Needs review
StatusFileSize
new1.31 KB

Re-rolled patch against a clean Entity API 7.x-1.x-dev. Lines changed from @@ -873,10 to 899, no conflicts.

alexander allen’s picture

Status: Needs review » Reviewed & tested by the community

Marking as RTBC.

fago’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
+++ b/modules/callbacks.inc
@@ -896,10 +896,18 @@ function entity_metadata_form_comment($comment) {
+  }
+  ¶
   $form_state['build_info']['args'] = array($account);

Unnecessary whitespace.

sonictruth’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new1.3 KB

How's this?

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 6: entity-issue-1921894-entity_metadata_form_user-2.patch, failed testing.

sonictruth’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new1.21 KB

Oops. This should be better.

fago’s picture

Thanks, committed.

fago’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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