/** * Resources form submit function. * * @param array $form * @param array $form_state * @return void */ function services_edit_form_endpoint_resources_submit($form, $form_state) { $endpoint = $form_state['values']['endpoint_object']; $resources = $form_state['input']['resources']; $class_names = services_operation_class_info(); // Iterate over the resources, its operation classes and operations. // The main purpose is to remove empty configuration for disabled elements. foreach ($resources as $resource_name => $resource) { if (empty($resource['alias'])) { unset($resource['alias']); } foreach ($class_names as $class_name => $info) { if (!empty($resource[$class_name])) { foreach ($resource[$class_name] as $op_name => $op) { // Remove the operation if it has been disabled. if (!$op['enabled']) { unset($resource[$class_name][$op_name]); } } } // Remove the operation class element if it doesn't // have any enabled operations. if (empty($resource[$class_name])) { unset($resource[$class_name]); } } // Remove the resource if it doesn't have any properties. if (empty($resource)) { unset($resources[$resource_name]); } else { $resources[$resource_name] = $resource; } } $endpoint->resources = $resources; services_endpoint_save($endpoint); drupal_set_message('Resources have been saved'); }
public function saveNewEndpoint() { $edit = $this->populateEndpointFAPI(); $endpoint = new stdClass(); $endpoint->disabled = FALSE; /* Edit this to true to make a default endpoint disabled initially */ $endpoint->api_version = 3; $endpoint->name = $edit['name']; $endpoint->title = $edit['title']; $endpoint->server = $edit['server']; $endpoint->path = $edit['path']; $endpoint->authentication = array('services_sessauth' => array()); $endpoint->resources = array('node' => array('alias' => '', 'operations' => array('create' => array('enabled' => 1), 'retrieve' => array('enabled' => 1), 'update' => array('enabled' => 1), 'delete' => array('enabled' => 1), 'index' => array('enabled' => 1))), 'system' => array('alias' => '', 'actions' => array('connect' => array('enabled' => 1), 'get_variable' => array('enabled' => 1), 'set_variable' => array('enabled' => 1))), 'taxonomy_term' => array('alias' => '', 'operations' => array('create' => array('enabled' => 1), 'retrieve' => array('enabled' => 1), 'update' => array('enabled' => 1), 'delete' => array('enabled' => 1)), 'actions' => array('selectNodes' => array('enabled' => 1))), 'taxonomy_vocabulary' => array('alias' => '', 'operations' => array('create' => array('enabled' => 1), 'retrieve' => array('enabled' => 1), 'update' => array('enabled' => 1), 'delete' => array('enabled' => 1)), 'actions' => array('getTree' => array('enabled' => 1))), 'user' => array('alias' => '', 'operations' => array('create' => array('enabled' => 1), 'retrieve' => array('enabled' => 1), 'update' => array('enabled' => 1), 'delete' => array('enabled' => 1), 'index' => array('enabled' => 1)), 'actions' => array('login' => array('enabled' => 1), 'logout' => array('enabled' => 1))), 'comment' => array('alias' => '', 'operations' => array('create' => array('enabled' => 1), 'retrieve' => array('enabled' => 1), 'update' => array('enabled' => 1), 'delete' => array('enabled' => 1)), 'actions' => array('loadNodeComments' => array('enabled' => 1), 'countAll' => array('enabled' => 1), 'countNew' => array('enabled' => 1))), 'file' => array('alias' => '', 'operations' => array('create' => array('enabled' => 1), 'retrieve' => array('enabled' => 1), 'delete' => array('enabled' => 1)), 'actions' => array('nodeFiles' => array('enabled' => 1))), 'echo' => array('alias' => '', 'operations' => array('index' => array('enabled' => 1)))); $endpoint->debug = 1; $endpoint->status = 1; services_endpoint_save($endpoint); $endpoint = services_endpoint_load($endpoint->name); if ($endpoint->name == $edit['name']) { $this->pass('Endpoint successfully created'); } else { $this->fail('Endpoint creation failed'); } $this->servicesGet($endpoint->path); return $endpoint; }
/** * services_edit_form_endpoint_resources_submit function. * * @param array $form * @param array $form_state * @return void */ function services_edit_form_endpoint_resources_submit($form, &$form_state) { $endpoint = $form_state['values']['endpoint_object']; $existing_resources = _services_build_resources(); // Apply the endpoint in a non-strict mode, so that the non-active resources // are preserved. _services_apply_endpoint($existing_resources, $endpoint, FALSE); $resources = $form_state['values']; $endpoint = $form_state['values']['endpoint_object']; foreach ($resources as $path => $state) { if (strpos($path, '-') === FALSE || empty($state)) { continue; } $split_path = explode('-', $path); $resource = $split_path[0]; $method = $split_path[1]; // If method is alias. if ($method == 'alias') { $final_resource[$resource]['alias'] = $state; continue; } // If it is action, relationship, or targeted action. if (isset($split_path[2])) { $final_resource[$resource][$split_path[2]][$method]['enabled'] = 1; continue; } // If it is operation. $final_resource[$resource]['operations'][$method]['enabled'] = 1; } $endpoint->resources = $final_resource; services_endpoint_save($endpoint); drupal_set_message(t('Resources have been saved')); }
public function saveNewEndpoint() { $edit = $this->populateEndpointFAPI(); $endpoint = new stdClass(); $endpoint->disabled = FALSE; /* Edit this to true to make a default endpoint disabled initially */ $endpoint->api_version = 3; $endpoint->name = $edit['name']; $endpoint->title = $edit['title']; $endpoint->server = $edit['server']; $endpoint->path = $edit['path']; $endpoint->authentication = array('services' => 'services'); $endpoint->server_settings = array('rest_server' => array('formatters' => array('json' => TRUE, 'bencode' => TRUE, 'rss' => TRUE, 'plist' => TRUE, 'xmlplist' => TRUE, 'php' => TRUE, 'yaml' => TRUE, 'jsonp' => FALSE, 'xml' => FALSE), 'parsers' => array('application/x-yaml' => TRUE, 'application/json' => TRUE, 'application/vnd.php.serialized' => TRUE, 'application/plist' => TRUE, 'application/plist+xml' => TRUE, 'application/x-www-form-urlencoded' => TRUE))); $endpoint->resources = array('comment' => array('operations' => array('create' => array('enabled' => 1), 'retrieve' => array('enabled' => 1), 'update' => array('enabled' => 1), 'delete' => array('enabled' => 1), 'index' => array('enabled' => 1)), 'actions' => array('countAll' => array('enabled' => 1), 'countNew' => array('enabled' => 1))), 'file' => array('operations' => array('create' => array('enabled' => 1), 'retrieve' => array('enabled' => 1), 'delete' => array('enabled' => 1), 'index' => array('enabled' => 1))), 'node' => array('operations' => array('retrieve' => array('enabled' => 1), 'create' => array('enabled' => 1), 'update' => array('enabled' => 1), 'delete' => array('enabled' => 1), 'index' => array('enabled' => 1)), 'relationships' => array('files' => array('enabled' => 1), 'comments' => array('enabled' => 1))), 'system' => array('actions' => array('connect' => array('enabled' => 1), 'get_variable' => array('enabled' => 1), 'set_variable' => array('enabled' => 1), 'del_variable' => array('enabled' => 1))), 'taxonomy_term' => array('operations' => array('retrieve' => array('enabled' => 1), 'create' => array('enabled' => 1), 'update' => array('enabled' => 1), 'delete' => array('enabled' => 1), 'index' => array('enabled' => 1)), 'actions' => array('selectNodes' => array('enabled' => 1))), 'taxonomy_vocabulary' => array('operations' => array('retrieve' => array('enabled' => 1), 'create' => array('enabled' => 1), 'update' => array('enabled' => 1), 'delete' => array('enabled' => 1), 'index' => array('enabled' => 1)), 'actions' => array('getTree' => array('enabled' => 1))), 'user' => array('operations' => array('retrieve' => array('enabled' => 1), 'create' => array('enabled' => 1), 'update' => array('enabled' => 1), 'delete' => array('enabled' => 1), 'index' => array('enabled' => 1)), 'actions' => array('login' => array('enabled' => 1), 'logout' => array('enabled' => 1), 'register' => array('enabled' => 1)))); $endpoint->debug = 1; $endpoint->export_type = FALSE; services_endpoint_save($endpoint); $endpoint = services_endpoint_load($endpoint->name); $this->assertTrue($endpoint->name == $edit['name'], t('Endpoint successfully created')); return $endpoint; }