The validation in #2483841 seems to cause issues when the user entity has a field attached to it.

There's a warning first:
Warning: array_merge(): Argument #1 is not an array in field_default_extract_form_values() (line 36 of /home/vagrant/sites-defaults/bcss/drupal/modules/field/field.default.inc).

Then the fatal error:
Recoverable fatal error: Argument 2 passed to drupal_array_get_nested_value() must be of the type array, null given, called in /home/vagrant/sites-defaults/bcss/drupal/modules/field/field.default.inc on line 38 and defined in drupal_array_get_nested_value() (line 6771 of /home/vagrant/sites-defaults/bcss/drupal/includes/common.inc).

These happen because $form in field_default_extract_form_values() is the form id "user_register_form", when it's expecting the full form array.

I've traced this back to the new call to user_register_validate() in _user_resource_create(), where the form ID is passed, but as we don't have the full form array at that point I'm a bit stumped on what to do next to fix this.

Comments

kylebrowning’s picture

Shit.

rakesh.nimje84@gmail.com’s picture

I am also facing the same issue. Any solution ?

light9’s picture

this headashe stopped my job

xanfar’s picture

I am using services version 7.x-3.13

I found the user_register_validate() function mentioned in the original post on line 339 of user_resource.inc

I was having this same problem also and found that if i got the form array first
$formForCheck = drupal_get_form('user_register_form');

then validated with that value. Validation seems to still work during my service calls
user_register_validate($formForCheck, $form_state);

DrupalChimp’s picture

Same issue.

Xanfar, suggestion definitely stops the error and creates the user but all the form field values are lost during drupal_process_form() in form.inc. as documented here https://www.drupal.org/node/1699288

Although I've just realised that's an old bug.

DrupalChimp’s picture

StatusFileSize
new657 bytes

Ok, not taking credit for this. That's all xanfar. But here is a patch.

xanfar’s picture

Thank You DrupalChimp.. so in our case since $form_state['values'] is being defined by the $account variable.
Should I be adding the line:
$form_check = drupal_get_form('user_register_form');
above any $form_state modifications (line 308).

When drupal_get_form() defines $form_state as an empty array... will this make a difference?

DrupalChimp’s picture

Status: Active » Needs review
mario_prkos’s picture

I can confirm that problem. I am using 7.13 version of module. Drupal version is 7.41.

Even if I put the patch values are not composed in function field_default_extract_form_values in field.default.inc which gives error Fatal error: Cannot unset string offsets in ...modules/field/field.default.inc on line 41. If I simple remove user_register_validation it works and validation is still perform. I tested with some garbage in data and use service to create user.

From documentation in code about drupal_form_submit function is visible that this function populates errors that are retrievable with form_get_errors. So it looks that this function performs validation. Test also confirms that.

I am not sure is this validation in function user_register_validate($formForCheck, $form_state) is really needed but anyway I would like to see other peoples opinions.

aron novak’s picture

@mario_prkos I can confirm what you say. resources/node_resource.inc does not do anything like that and indeed drupal_form_submit does validation, as we just check it later. And hard-coding a single validation callback is quite problematic. What if someone alters it for a good reason via Form API? I think we can safely get rid of couple of lines here and let drupal_form_submit does the validation, without any kind of performance optimization that decreases the flexibility.

mario_prkos’s picture

StatusFileSize
new834 bytes

Thanks Aron for insight. Here is the patch.

xanfar’s picture

I have to agree with Mario and Aron. #11 seems to be a working solution for me and I can confirm that validation still occurs. Thank you

kylebrowning’s picture

Status: Needs review » Reviewed & tested by the community

kylebrowning’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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