This function only performs entity_form_field_validate('user', $form, $form_state);, which will validate the user account bundle, which is not there when $category != 'account'.

function user_profile_form($form, &$form_state, $account, $category = 'account') {
  ...
  $form['#user_category'] = $category;

  if ($category == 'account') {
    user_account_form($form, $form_state);
    // Attach field widgets.
    field_attach_form('user', $account, $form, $form_state);
  }
  ...
  $form['#validate'][] = 'user_profile_form_validate';
  // Add the final user profile form submit handler.
  $form['#submit'][] = 'user_profile_form_submit';

  return $form;
}

/**
 * Validation function for the user account and profile editing form.
 */
function user_profile_form_validate($form, &$form_state) {
  entity_form_field_validate('user', $form, $form_state);
}

This can lead to errors during validation as these fields are still validated. See #1200890: Fields that trigger errors using hook_field_validate() trigger PHP errors

Comments

alan d.’s picture

Status: Active » Needs review
alan d.’s picture

It would make sense to extend this to the submit handler as well... This really needs review by the field maintainers!

Status: Needs review » Needs work
alan d.’s picture

I think that this strongly suggests that removing validation could also be a bad idea.

Moving into the field system, a safe check could be the existence of the instance in the results from field_form_get_state(), again requiring feedback from others.

alan d.’s picture

Status: Needs work » Needs review
alan d.’s picture

Priority: Major » Normal

Major in regards to the Name Field module, but not in the grander scheme :)

It would be great to have someone to review the last patch, all it does is to check that there was a valid form element returned from field_form_get_state() during field widget validation. [One singular isset() check]. This is a complete show stopper for using this field in Profile2, and may it effect other multi-component fields too.

alan d.’s picture

Status: Needs review » Fixed

Some quick tests seem to show that this was strangely resolved somewhere else in Drupal 7.4 albeit I can not see where!

Status: Fixed » Closed (fixed)

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