I'm sorry to be brief on this issue. But I do not have much time right now.
To reproduce:
Drupal-7.43 Services-3.13 Custom fields for user (based on core functionality) - at least one field.
User register functionality not working.
JS:
jQuery.ajax({method:'POST', url: '/api/user/register', data: {mail:'test@example.com', name:'Care Bear',pass:'1290'} }).always(function(d){console.log(d.responseText+"\n"+d.status+"="+d.statusText);});
Error:
Recoverable fatal error: Argument 2 passed to drupal_array_get_nested_value() must be of the type array, null given, called in /Users/carebear/Dev/d7/modules/field/field.default.inc on line 38 and defined in drupal_array_get_nested_value() (line 6787 of /Users/carebear/Dev/d7/includes/common.inc).
500=Service unavailable (with message)
<em class="placeholder">Recoverable fatal error</em>: Argument 2 passed to drupal_array_get_nested_value() must be of the type array, null given, called in /Users/carebear/Dev/d7/modules/field/field.default.inc on line 38 and defined in <em class="placeholder">drupal_array_get_nested_value()</em> (line <em class="placeholder">6787</em> of <em class="placeholder">/Users/carebear/Dev/d7/includes/common.inc</em>).
500=Service unavailable (with message)
This has happened because of validation process against fields (admin/config/people/accounts/fields)
The following code responsible:
services/resources/user_resource.inc:339
<?php
function _user_resource_create($account) {
...
// Ensure this is validated, as drupal_form_submit will not call validation.
user_register_validate('user_register_form', $form_state);
$errors = form_get_errors();
...
?>
Technically if you follow the function calls you will end up here:
DrupalRoot/modules/field/field.default.inc:35
<?php
field_default_extract_form_values($entity_type, $entity, $field, $instance, $langcode, &$items, $form, &$form_state) {
$path = array_merge($form['#parents'], array($field['field_name'], $langcode));
$key_exists = NULL;
$values = drupal_array_get_nested_value($form_state['values'], $path, $key_exists);
if ($key_exists) {
....
?>
As you can see the function expect the $form to be an array, and should at least have one element named '#parents'.
We are firing form with string.
but it should be with full loaded form
eg.
<?php
user_register_validate($form, $form_state);
?>Solution:
This is only quick fix. Please provide decent patch.
So quick solution for everyone else using services in production:
Insert the code in the appropriate location inside
services/resources/user_resource.inc:336
<?php
...
// Execute the register form.
$form_state['programmed_bypass_access_check'] = FALSE;
/* Start hack */
$form_state += form_state_defaults(); // adding some defaults.
$form_state += array(
// 'input'=>$form_state['values'], // not sure about this. it may skip all validations.
// 'programmed'=>TRUE // also not sure...
);
$form = drupal_retrieve_form('user_register_form', $form_state);
// Ensure this is validated, as drupal_form_submit will not call validation.
// user_register_validate('user_register_form', $form_state); // original call - put it in comment
user_register_validate($form, $form_state); // new call
/* End hack */
$errors = form_get_errors();
...
?>This will load the form first, add some defaults, and only then will start validation on it.
Good luck!
Comments
Comment #2
marcingy commentedThis is fixed in #2543010: Validation causes calls to user/create to fail when the user has a field attached.