You are here

function _webform_resource_definition in Webform Service 7.4

Same name and namespace in other branches
  1. 6.3 resources/webform_resource.inc \_webform_resource_definition()

The webform resource definition.

Return value

array

1 call to _webform_resource_definition()
webform_service_services_resources in ./webform_service.module

File

resources/webform_resource.inc, line 8

Code

function _webform_resource_definition() {

  // Define the resources.
  $resources = array();

  // Get all the webform types.
  $types = webform_variable_get('webform_node_types');

  // Iterate through the webform types.
  foreach ($types as $type) {

    // Add the resource type.
    $resources[$type] = array(
      'operations' => array(
        'retrieve' => array(
          'callback' => 'webform_service_get_resource',
          'args' => array(
            array(
              'name' => 'uuid',
              'optional' => FALSE,
              'source' => array(
                'path' => 0,
              ),
              'type' => 'string',
              'description' => 'The uuid of the node to get',
            ),
          ),
          'access callback' => 'webform_service_resource_access',
          'access arguments' => array(
            'view',
            $type,
          ),
          'access arguments append' => TRUE,
        ),
        'create' => array(
          'file' => array(
            'type' => 'inc',
            'module' => 'webform_service',
            'name' => 'resources/webform_resource',
          ),
          'callback' => 'webform_service_resource_create',
          'args' => array(
            array(
              'name' => 'webform',
              'optional' => FALSE,
              'source' => 'data',
              'description' => 'All the elements that make up the webform entity.',
              'type' => 'array',
              'default value' => array(),
            ),
            array(
              'name' => 'type',
              'optional' => TRUE,
              'type' => 'string',
              'description' => 'Webform Type',
              'default value' => $type,
              'source' => array(
                'param' => 'type',
              ),
            ),
          ),
          // args
          'access callback' => 'webform_service_resource_access',
          'access arguments' => array(
            'create',
            $type,
          ),
          'access arguments append' => TRUE,
        ),
        // create
        'update' => array(
          'file' => array(
            'type' => 'inc',
            'module' => 'webform_service',
            'name' => 'resources/webform_resource',
          ),
          'callback' => 'webform_service_resource_update',
          'args' => array(
            array(
              'name' => 'uuid',
              'optional' => FALSE,
              'source' => array(
                'path' => 0,
              ),
              'type' => 'string',
              'description' => 'The uuid of the node to get',
            ),
            array(
              'name' => 'node',
              'optional' => FALSE,
              'source' => 'data',
              'description' => 'The node data to update',
              'type' => 'array',
            ),
          ),
          'access callback' => 'webform_service_resource_access',
          'access arguments' => array(
            'update',
            $type,
          ),
          'access arguments append' => TRUE,
        ),
        'delete' => array(
          'file' => array(
            'type' => 'inc',
            'module' => 'webform_service',
            'name' => 'resources/webform_resource',
          ),
          'callback' => 'webform_service_resource_delete',
          'args' => array(
            array(
              'name' => 'uuid',
              'optional' => FALSE,
              'source' => array(
                'path' => 0,
              ),
              'type' => 'string',
            ),
          ),
          'access callback' => 'webform_service_resource_access',
          'access arguments' => array(
            'delete',
            $type,
          ),
          'access arguments append' => TRUE,
        ),
        'index' => array(
          'file' => array(
            'type' => 'inc',
            'module' => 'webform_service',
            'name' => 'resources/webform_resource',
          ),
          'help' => t('Return all webforms.'),
          'callback' => '_webform_resource_index',
          'args' => array(
            array(
              'name' => 'page',
              'optional' => TRUE,
              'type' => 'int',
              'description' => 'The zero-based index of the page to get, defaults to 0.',
              'default value' => 0,
              'source' => array(
                'param' => 'page',
              ),
            ),
            array(
              'name' => 'pagesize',
              'optional' => TRUE,
              'type' => 'int',
              'description' => 'Number of records to get per page.',
              'default value' => variable_get('services_node_index_page_size', 20),
              'source' => array(
                'param' => 'pagesize',
              ),
            ),
            array(
              'name' => 'type',
              'optional' => TRUE,
              'type' => 'string',
              'description' => 'Webform Type',
              'default value' => $type,
              'source' => array(
                'param' => 'type',
              ),
            ),
          ),
          'access arguments' => array(
            'access content',
          ),
        ),
      ),
      'relationships' => array(
        'submissions' => array(
          'help' => t('Retrieve the submissions provided a webform.'),
          'callback' => 'webform_service_submission_index',
          'args' => array(
            array(
              'name' => 'uuid',
              'optional' => FALSE,
              'source' => array(
                'path' => 0,
              ),
              'type' => 'string',
              'description' => t('The uuid of the webform you want the relationship for.'),
            ),
            array(
              'name' => 'page',
              'optional' => TRUE,
              'type' => 'int',
              'description' => 'The zero-based index of the page to get, defaults to 0.',
              'default value' => 0,
              'source' => array(
                'param' => 'page',
              ),
            ),
            array(
              'name' => 'pagesize',
              'optional' => TRUE,
              'type' => 'int',
              'description' => 'Number of records to get per page.',
              'default value' => variable_get('services_node_index_page_size', 20),
              'source' => array(
                'param' => 'pagesize',
              ),
            ),
            array(
              'name' => 'parameters',
              'optional' => TRUE,
              'type' => 'array',
              'description' => 'Parameter filters to apply to the index.',
              'default value' => array(),
              'source' => array(
                'param' => 'parameters',
              ),
            ),
          ),
          'access arguments' => array(
            'access content',
          ),
        ),
      ),
    );
  }

  // Return the resources.
  return $resources;
}