For my current project I need to use the 'unique' validator plugin for a custom (cck) field.
But after enabling the plugin, the user services endpoint stop working on update operation with a form validation error on my custom unique field.
The cause of the error is that the unique plugin failed to retrieve the user id (uid), so it always says the unique field value is already in use.
To fix the error I modify the "field_validation/plugins/validator/field_validation_unique_validator.inc" by adding the following lines near line 48 :
if ($this->rule->entity_type == 'user' && empty($id) && module_exists('services')) {
// retrieve current service endpoint name
$endpoint_name = services_get_server_info('endpoint');
if (!empty($endpoint_name)) {
$endpoint = services_endpoint_load($endpoint_name);
if (isset($endpoint->resources['user'])) {
$endpoint_path = $endpoint->path;
$resource_alias = $endpoint->resources['user']['alias'];
// build user service resource path
$path_elements = array();
$path_elements = array_merge($path_elements, explode('/', $endpoint_path));
$path_elements = array_merge($path_elements, explode('/', $resource_alias));
$path_length = count($path_elements);
// check if user service resource (paths match) ?
$is_user_resource = TRUE;
for ($i = 0; $i < $path_length; $i++) {
if ($path_elements[$i] !== arg($i)) {
$is_user_resource = FALSE;
break;
}
}
// if user resource, check for user id arguments
if ($is_user_resource && is_numeric(arg($path_length))) {
$id = arg($path_length);
}
}
}
}
Is there a better way to do this ?
Is services integration already planned ?
Comments
Comment #1
g089h515r806 CreditAttribution: g089h515r806 commentedIt does not support Service now. Maybe support it in Drupal8.
Comment #2
g089h515r806 CreditAttribution: g089h515r806 commented